Download ebooks file Using Asyncio in Python Understanding Python s Asynchronous Programming Features Caleb Hattingh all chapters
Download ebooks file Using Asyncio in Python Understanding Python s Asynchronous Programming Features Caleb Hattingh all chapters
com
https://textbookfull.com/product/using-asyncio-in-python-
understanding-python-s-asynchronous-programming-features-
caleb-hattingh/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/using-asyncio-in-python-3-caleb-
hattingh/
textboxfull.com
https://textbookfull.com/product/introduction-to-computation-and-
programming-using-python-with-application-to-understanding-data-
guttag/
textboxfull.com
https://textbookfull.com/product/expert-twisted-event-driven-and-
asynchronous-programming-with-python-1st-edition-mark-williams/
textboxfull.com
https://textbookfull.com/product/expert-twisted-event-driven-and-
asynchronous-programming-with-python-1st-edition-mark-williams-2/
textboxfull.com
Python Programming Using Problem Solving Approach Thareja
Reema
https://textbookfull.com/product/python-programming-using-problem-
solving-approach-thareja-reema/
textboxfull.com
https://textbookfull.com/product/powerful-python-the-most-impactful-
patterns-features-and-development-strategies-modern-python-provides-
maxwell/
textboxfull.com
https://textbookfull.com/product/python-descriptors-understanding-and-
using-the-descriptor-protocol-1st-edition-jacob-zimmerman/
textboxfull.com
https://textbookfull.com/product/introduction-to-computation-and-
programming-using-python-3rd-edition-john-v-guttag/
textboxfull.com
Using Asyncio in Python
Understanding Python’s Asynchronous Programming
Features
Caleb Hattingh
Using Asyncio in Python
by Caleb Hattingh
Copyright © 2020 Tekmoji Pty Ltd. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North,
Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales
promotional use. Online editions are also available for most titles
(http://oreilly.com). For more information, contact our
corporate/institutional sales department: 800-998-9938 or
[email protected].
Python 3.4 introduced the asyncio library, and Python 3.5 produced
the async and await keywords to use it palatably. These new
additions allow so-called asynchronous programming.
All of these new features, which I’ll refer to under the single name
Asyncio, have been received by the Python community somewhat
warily; a segment of the community seems to see them as complex
and difficult to understand. This view is not limited to beginners:
several high-profile contributors to the Python community have
expressed doubts about the complexity of the Asyncio API in Python,
and educators in the community have expressed concern about how
best to teach Asyncio to students.
Most people with a few years’ experience with Python have used
threads before, and even if you haven’t, you are still likely to have
experienced blocking. For example, if you’ve written programs using
the wonderful requests library, you will surely have noticed that your
program pauses for a bit while it does requests.get(url); this is
blocking behavior.
For one-off tasks, this is fine; but if you want to fetch ten thousand
URLs simultaneously, it’s going to be difficult to use requests. Large-
scale concurrency is one big reason to learn and use Asyncio, but
the other big attraction of Asyncio over preemptive threading is
safety: it will be much easier for you to avoid race condition bugs
with Asyncio.
My goal with this book is to give you a basic understanding of why
these new features have been introduced and how to use them in
your own projects. More specifically, I aim to provide the following:
A critical comparison of asyncio and threading for
concurrent network programming
An understanding of the new async/await language syntax
A general overview of the new asyncio standard library
features in Python
Detailed, extended case studies with code, showing how to
use a few of the more popular Asyncio-compatible third-
party libraries
We’ll begin with a story that illustrates the shift in thinking that must
accompany a transition from threaded to async programming. Then,
we’ll take a look at the changes that were made in the Python
language itself to accommodate async programming. Finally, we’ll
explore some of the ways in which these new features can be used
most effectively.
The new Asyncio features are not going to radically change the way
you write programs. They provide specific tools that make sense
only for specific situations; but in the right situations, asyncio is
exceptionally useful. In this book, we’re going to explore those
situations and how you can best approach them by using the new
Asyncio features.
Constant width
Used for program listings, as well as within paragraphs to refer to
program elements such as variable or function names, databases,
datatypes, environment variables, statements, and keywords.
TIP
This element signifies a tip or suggestion.
NOTE
This element signifies a general note.
WARNING
This element indicates a warning or caution.
NOTE
For more than 40 years, O’Reilly Media has provided technology and
business training, knowledge, and insight to help companies succeed.
Our unique network of experts and innovators share their knowledge
and expertise through books, articles, conferences, and our online
learning platform. O’Reilly’s online learning platform gives you on-
demand access to live training courses, in-depth learning paths,
interactive coding environments, and a vast collection of text and
video from O’Reilly and 200+ other publishers. For more information,
please visit http://oreilly.com.
How to Contact Us
Please address comments and questions concerning this book to the
publisher:
Sebastopol, CA 95472
707-829-0104 (fax)
We have a web page for this book, where we list errata, examples,
and any additional information. It can be accessed at
https://oreil.ly/using-asyncio-in-python.
Email [email protected] to comment or ask technical
questions about this book.
For more information about our books, courses, conferences, and
news, see our website at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
Many thanks to Ashwini Balnaves and Kevin Baker for working
through very early drafts of this book and providing invaluable
feedback. I am deeply grateful to Yury Selivanov for making precious
time available to review an earlier incarnation of this book, when it
was first published as an O’Reilly report. Finally, I would also like to
thank the team at O’Reilly for their excellent editorial support.
Chapter 1. Introducing
Asyncio
That’s it.
Threading—as a programming model—is best suited to certain kinds
of computational tasks that are best executed with multiple CPUs
and shared memory for efficient communication between the
threads. In such tasks, the use of multicore processing with shared
memory is a necessary evil because the problem domain requires it.
Network programming is not one of those domains. The key insight
is that network programming involves a great deal of “waiting for
things to happen,” and because of this, we don’t need the operating
system to efficiently distribute our tasks over multiple CPUs.
Furthermore, we don’t need the risks that preemptive multitasking
brings, such as race conditions when working with shared memory.
However, there is a great deal of misinformation about other
supposed benefits of event-based programming models. Here are a
few of the things that just ain’t so:
Asyncio will make my code blazing fast.
Unfortunately, no. In fact, most benchmarks seem to show that
threading solutions are slightly faster than their comparable
Asyncio solutions. If the extent of concurrency itself is considered
a performance metric, Asyncio does make it a bit easier to create
very large numbers of concurrent socket connections, though.
Operating systems often have limits on how many threads can be
created, and this number is significantly lower than the number
of socket connections that can be made. The OS limits can be
changed, but it is certainly easier to do with Asyncio. And while
we expect that having many thousands of threads should incur
extra context-switching costs that coroutines avoid, it turns out
to be difficult to benchmark this in practice.1 No, speed is not the
benefit of Asyncio in Python; if that’s what you’re after, try
Cython instead!
Asyncio makes threading redundant.
Definitely not! The true value of threading lies in being able to
write multi-CPU programs, in which different computational tasks
can share memory. The numerical library numpy, for instance,
already makes use of this by speeding up certain matrix
calculations through the use of multiple CPUs, even though all
the memory is shared. For sheer performance, there is no
competitor to this programming model for CPU-bound
computation.
1 Research in this area seems hard to find, but the numbers seem to be
around 50 microseconds per threaded context switch on Linux on modern
hardware. To give a (very) rough idea: one thousand threads implies 50 ms
total cost just for the context switching. It does add up, but it isn’t going to
wreck your application either.
2 The global interpreter lock (GIL) makes the Python interpreter code (not
your code!) thread-safe by locking the processing of each opcode; it has the
unfortunate side effect of effectively pinning the execution of the interpreter
to a single CPU, and thus preventing multicore parallelism.
3 This is similar to why JavaScript lacks a GIL “problem”: there is only one
thread.
Chapter 2. The Truth About
Threads
Benefits of Threading
These are the main benefits of threading:
Ease of reading code
Your code can run concurrently, but still be set out in a very
simple, top-down linear sequence of commands to the point
where—and this is key—you can pretend, within the body of your
functions, that no concurrency is happening.
def worker(data):
<process the data>
with Executor(max_workers=10) as exe:
future = exe.submit(worker, data)
TIP
Raymond Hettinger presented several great guidelines for safer
threaded code at PyCon Russia 2016 and PyBay 2017. I strongly urge
you to add these videos to your watch list.
Drawbacks of Threading
[N]ontrivial multithreaded programs are incomprehensible to
humans. It is true that the programming model can be improved
through the use of design patterns, better granularity of atomicity
(e.g., transactions), improved languages, and formal methods.
However, these techniques merely chip away at the unnecessarily
enormous non-determinism of the threading model. The model
remains intrinsically intractable.
—Edward A. Lee “The Problem with Threads”
The drawbacks of threading have been mentioned in a few other
places already, but for completeness let’s collect them here anyway:
Threading is difficult
Threading bugs and race conditions in threaded programs are the
hardest kinds of bugs to fix. With experience, it is possible to
design new software that is less prone to these problems, but in
nontrivial, naively designed software, they can be nearly
impossible to fix, even by experts. Really!
# threadmem.py
import os
from time import sleep
from threading import Thread
threads = [
Thread(target=lambda: sleep(60)) for i in range(10000)
]
[t.start() for t in threads]
print(f'PID = {os.getpid()}')
[t.join() for t in threads]
* * * * * *
I may be doing injustice to my friend the forger, but he gave me the
impression that he considered himself to be, on the whole, a rather
admirable character. His proposed change of business seemed to be
rather a concession to the prejudices of the legal profession than the
result of any personal scruple. As he saw himself he was a man of
idealistic temper whose ideals conflicted with social usage. Society was
all the time getting into his way, and in the inevitable collisions he had
usually the worst of it. He regretted this, but he bore no malice. By the
time a man has reached middle life and accumulated a good deal of
experience he takes the world as he finds it.
He had encased himself in a moral system which was self-consistent and
which explained to his own satisfaction all that had happened to him. One
thing fitted into another, and there was no room for self-reproach.
* * * * * *
Many attempts have been made to depict the character of an
accomplished scamp. But Gil Blas and Roderick Random and Jonathan
Wild the Great are after all seen from the outside. The author may attempt
to do them justice, but there is a vein of irony that reveals a judgment of
his own. They lack the essential element of incorrigibility, which is that the
scamp does not suspect himself, has not found himself out.
No novelist has ever been able to give such a portraiture of a complacent
criminal as was given a century ago in the autobiography of Stephen
Burroughs.
Burroughs was the son of a worthy clergyman of Hanover, New
Hampshire, and from the outset was looked upon as a black sheep. As a
mere boy he ran away from home and joined the army, and then with
equal irresponsibility deserted. He became a ship’s surgeon, a
privateersman, then a self-ordained minister, a counterfeiter, a teacher of
youth, a founder of libraries, and a miscellaneous philanthropist. He was a
patriot and an optimist and an enthusiastic worker in the cause of general
education. He was chock-full of fine sentiment and had a gift for its
expression. He enjoyed doing good, though in his own way, and never
neglected any opportunity to rebuke those who he felt were in the wrong.
He had a desire to reform the world, and had no doubt of the plans which
he elaborated. He was capable on occasions of acts of magnanimity,
which, while not appreciated by the public, gave him great pleasure in the
retrospect. The intervals between his various enterprises were spent in
New England jails. These experiences only deepened his love of liberty,
which was one of the passions of his life.
Burroughs had a happy disposition that enabled him to get a measure of
satisfaction out of all the vicissitudes of his life. He had learned neither to
worry nor to repine. He was not troubled by the harsh judgments of his
fellow men, for he had learned to find his happiness in the approbation of
his own conscience.
He writes: “I possess an uncommon share of sensibility, and at the same
time maintain an equality of mind that is uncommon, particularly in the
midst of those occurrences which are calculated to wound the feelings. I
have learned fortitude in the school of adversity. In draining the cup of
bitterness to its dregs, I have been taught to despise the occurrences of
misfortune. This one thing I fully believe, that our happiness is more in our
power than is generally thought, or at least we have the ability of
preventing that misery which is so common to unfortunate situations. No
state or condition in life, but from which we may (if we exercise that
reason which the God of Nature has given us) draw comfort and
happiness. We are too apt to be governed by the opinions of others, and if
they think our circumstances unhappy, to consider them so ourselves, and
of course make them so. The state of mind is the only criterion of
happiness or misery.”
It was from this lofty point of view that Stephen Burroughs wrote the
history of his own life. His tendency to didacticism interferes with the
limpid flow of the narrative. Sometimes a whole chapter will be given over
to moralizings, but the observations are never painful. They all reveal the
author’s cheerful acquiescence in the inevitability of his own actions.
Along with this there is the air of chastened surprise over the fact that he
was made the object of persecution.
At the very beginning of the narrative one recognizes an independence
which would do credit to a better man. In New England, clergymen have
always been looked upon as making good ancestors, and Burroughs
might have been pardoned if he had shown some family pride. From this
weakness he was free. “I am,” he says, “the only son of a clergyman,
living in Hanover, in the State of New Hampshire; and were any to expect
merit from their parentage, I might justly look for that merit. But I am so far
a Republican that I consider a man’s merit to rest entirely with himself,
without any regard to family, blood, or connection.”
The accounts of the escapades of his boyhood are intermingled with
dissertations on the education of youth. “I have been in the habit of
educating youth for seven years, constantly; in the course of my business
I have endeavored to study the operations of the human heart, that I
might be able to afford that instruction which would be salutary; and in this
I find one truth clearly established, viz.: a child will endeavor to be what
you make him think mankind in general are.”
The neglect of this truth on the part of his parents and teachers was the
cause of much annoyance to Burroughs. Throughout his life he was the
innocent victim of an educational mistake. Though after a while he
learned to forgive the early injustice, one can see that it rankled. He
endeavored to think well of mankind in general, but it was more difficult
than if he had been habituated to the exercise in infancy.
At Dartmouth young Burroughs was peculiarly unfortunate; he fell into bad
company. As an unkind fate would have it, his room-mate was an
exemplary young man who was studying for the ministry. It appears that
this misguided youth attempted to entice him into what he describes as “a
sour, morose, and misanthropic line of conduct.” Nothing could have been
more disastrous. “To be an inmate with such a character, you will readily
conceive, no way comported with a disposition like mine, and
consequently we never enjoyed that union and harmony of feeling in our
intercourse as room-mates which was necessary for the enjoyment of
social life.”
To the malign influence of his priggish room-mate several misfortunes
were attributed. In endeavoring to restore the moral equilibrium which had
been disturbed by the too great scrupulosity of his chum, he exerted too
much strength in the other direction. The result was that “a powerful
triumvirate” was formed against him in the Faculty. The triumvirate
triumphed and his connection with Dartmouth ended suddenly.
This gave occasion to a chapter on the failure of the institutions of
learning to prepare for real life. The author declares “more than one half
of the time spent in the universities, according to their present
establishment on this continent, is thrown away, and that my position is
founded in fact I will endeavor to prove.”
I do not see how his argument is affected by the fact to which the editor
calls attention in a carping footnote. “It is not strange that the author
should reason in this manner. He was expelled from college in the second
quarter of his second year, and in fact he studied but little while he was a
member.” The editor, I fear, had a narrow mind and judged according to
an academic standard which Burroughs would have despised.
From the uncongenial limitations of a college town it was a satisfaction to
escape to sea. Here Burroughs’s versatility stood him in good stead.
“Having no doctor engaged, I undertook to act in that capacity; and after
obtaining the assistance, advice, and direction of an old practitioner,
together with marks set on each parcel of medicine, I thought myself
tolerably well qualified to perform the office of a physician on board the
ship.”
From his seafaring life Burroughs returned with his reputation under a
cloud. There were ugly rumors afloat which were readily believed by a
censorious world. For once he confesses that his philosophy failed him. “I
returned to my father’s house sunken and discouraged; the world
appeared a gloomy chaos; the sun arose to cast a sickly glimmer on
surrounding objects; the flowers of the field insulted my feelings with their
gayety and splendor; the frolicsome lamb, the playful kitten, and the antic
colt were beheld with those painful emotions which are beyond
description. Shall all nature, shall the brute creation break out into
irregular transports, by the overflowing of pleasing sensations, whilst I am
shut out from even the dim rays of hope?”
Certainly not. To a mind constituted as was his there was an absurdity in
the very suggestion. The brute creation should not have any monopoly of
comfortable sensations, so he cheered up immediately and spent the next
year loafing around his father’s house.
He had been on the coast of Africa and had taken part in some strange
scenes, but his moral sense had not been blunted to such an extent that
he could not grieve over some infractions of the moral law which he
observed in peaceful Hanover. He regretted that he had been led
inadvertently by a young man named Huntington to join a party which
robbed a farmer’s beehive.
“For some unaccountable reason or other, youth are carried away with
false notions of right and wrong. I know, for instance, that Huntington
possessed those principles of integrity that no consideration would have
induced him to deprive another of any species of property, except fruit,
bees, pigs, and poultry. And why it is considered by youth that depriving
another of these articles is less criminal than stealing any other kind of
property, I cannot tell.”
Burroughs himself was inclined to take a harsher view of these
transgressions than he did of some others; for example, of counterfeiting,
in which he was afterwards for a time engaged during one of his brief
pastorates.
The argument by which his scruples in this particular were overcome are
worth repeating. The law was indeed violated in its letter, but might not a
justification be found by one who interpreted it in a large spirit of charity?
“Money is of itself of consequence only as we annex to it a nominal value
as the representation of property. Therefore we find the only thing
necessary to make a matter valuable is to induce the world to deem it so;
and let that esteem be raised by any means whatever, yet the value is the
same, and no one becomes injured by receiving it at the valuation.”
The principle of fiat money having been established, the only question
that remained was whether the circumstances of the times were such as
to justify him in issuing the fiat. The answer was in the affirmative. “That
an undue scarcity of cash now prevails is a truth too obvious for me to
attempt to prove. Hence whoever contributes to increase the quantity of
cash does not only himself but likewise the community an essential
benefit.”
It was in his attempt to benefit the community in this way that he first
experienced the ingratitude of republics, being landed in the Northampton
jail.
But to see Burroughs at his best one must enter into his thoughts at that
crisis in his life when he determined that his true vocation was preaching.
He lingers fondly on his emotions at that period. It was at a time when he
had been driven out of Hanover for conduct which had outraged the
feelings of that long-suffering community.
“One pistareen was all the ready cash I had on hand, and the suddenness
with which I departed deprived me of the chance to raise more. Traveling
on leisurely I had time for reflection.”
As was usually the case when he reflected, he grew more serene and
enjoyed a frame of mind that bordered on the heroic.
“I began to look about me to see what was to be done in my present
situation and to what business I could turn my attention. The practice of
law, which would have been most to my mind, I could not undertake until I
had spent some time in the study, which would have been attended with
expense far beyond my abilities; therefore this object must be laid aside.
Physic was under the same embarrassments; business in the mercantile
line I could not pursue for want of capital. ... What can be done? There is
one thing, said contrivance, that you can do, and it will answer your
purpose—preach.”
The idea came to him as an inspiration, but immediately there was
suggested an objection which to a less resourceful mind would have
seemed insuperable. “What an appearance should I make in my present
dress? which consisted of a light gray coat, with silver-plated buttons,
green vest, and red velvet breeches.”
Down the Connecticut valley he trudged, calling to mind his father’s old
sermons and gradually working himself into a state of pious rapture. The
heart of no young pulpiteer beat with more appropriate emotions than his,
when on the next Sunday, under an assumed name, he preached his first
sermon in the village of Ludlow. “I awoke with anxious palpitation for the
issue of the day. I considered this as the most important scene of my life
—that, in a great measure, my future happiness or wretchedness
depended on my conduct this day. The time for assembling approached! I
saw the people come together. My feelings were up in arms against me,
my heart would almost leap into my mouth. What a strange thing, said I, is
man! Why am I thus perturbated by these whimsical feelings!”
The moment he began the service these perturbations came to an end.
Words came in a steady flow, and he felt sure that he had found his true
calling in life. “No monarch when seated on a throne had more sensible
feelings of prosperity than what I experienced at this time.”
The neighboring town of Pelham being without a minister, Burroughs
presented himself as a candidate, and was enthusiastically accepted. He
made a specialty of funeral sermons, and was soon in demand in all the
surrounding country. It was at this time also that he became acquainted
with the coiner who showed him how he might surreptitiously increase the
amount of cash in circulation. All went well till an enemy appeared who
called him by name and revealed his antecedents. All Pelham was in an
uproar, for the Pelhamites were “a people generally possessing violent
passions, which, once disturbed, raged uncontrolled by the dictates of
reason, unpolished in their manners, possessing a jealous disposition,
and either very friendly or very inimical, not knowing a medium between
these extremes.”
In this case they suddenly became very inimical, and Burroughs was
again compelled to depart under cover of darkness. His night thoughts
were always among his very best.
“Journeying on, I had time for reflection. At the dead of night—all alone—
reflection would have its operation. A very singular scene have I now
passed through, said I, and to what does it amount? Have I acted with
propriety as a man, or have I deviated from the path of rectitude? I have
had an unheard-of, disagreeable part to act; I do not feel entirely satisfied
with myself in this business, and yet I do not know how I could have done
otherwise, and have made the matter better. My situation has been such
that I have violated the principle of veracity which we implicitly pledge
ourselves to maintain towards each other, as a general thing, in society.
Whether my peculiar circumstances would warrant such a line of
procedure is the question. I know many things will be said in favor of it as
well as against it.”
From this difficult question of casuistry he found relief in reverting to the
one instance in which he had been clearly wrong, viz., joining the young
men in Hanover in their raid on the farmer’s beehive. “My giving
countenance to an open breach of the laws of the land in the case of the
bees was a matter in which I was justly reprehensible; but that matter is
now past. I must take things as they are, and under these circumstances
do the best I can. I know the world will blame me, but I wish to justify my
conduct to myself, let the world think what it may.”
In this endeavor he was highly successful; and as he walked on, his
spirits rose. He contrasted his own clear views with the muddled ideas of
his late parishioners. “They understand the matter in the gross, that I have
preached under a fictitious name and character, and consequently have
roused many ideas in the minds of the people not founded on fact.
Therefore they concluded from this general view the whole to be founded
on wrong. The name impostor is therefore easily fixed on my character.
An impostor, we generally conceive, puts on feigned appearances in
order to enrich or aggrandize himself to the damage of others. That this is
not the case with me in this transaction, I think is clear. That I have aimed
at nothing but the bare necessaries of life, is a fact.”
Having thus cleared himself of the charge of imposture, he determined to
rest his case on the broad ground of religious liberty. “That I have a good
and equitable right to preach, if I choose and others choose to hear me, is
a truth of which I entertain no doubt.”
When he was pursued into the borders of the town of Rutland, it was too
much for his patience. “I turned and ran about twenty rods down a small
hill, and the Pelhamites all after me, hallooing with all their might, ‘Stop
him! stop him!’ To be pursued like a thief, an object of universal
speculation to the inhabitants of Rutland, gave me very disagreeable
sensations, which I determined not to bear. I therefore stopped, took up a
stone, and declared that the first who should approach me I would kill on
the spot. To hear such language and to see such a state of determined
defiance in one whom they had lately reverenced as a clergyman struck
even the people of Pelham with astonishment and fear.”
By the way, there follows a scene which makes us suspect that parts of
Massachusetts in the good old days may have had a touch of “the wild
West.” The two deacons who were leaders of the mob drew attention to
the fact that besides having come to them under false pretenses
Burroughs had absconded with five dollars that had been advanced on
his salary. He owed them one sermon which was theirs of right. In the
present excited state of public opinion it was obviously impossible for
Burroughs to deliver the sermon, but it was suggested that he might give
an equivalent. A peacemaker intervened, saying, “Wood keeps an
excellent tavern hard by; I propose for all to move up there.” This proposal
was accepted by all. “I therefore came down, and we all went up towards
the tavern. I called for drink, according to the orator’s advice, to the
satisfaction of all.”
After that the career of Burroughs went on from bad to worse, but never
was he without the inner consolations that belong to those who are
misunderstood by the world. Even when he unsuccessfully sought to set
fire to the jail he was full of fine sentiments borrowed from Young’s “Night
Thoughts.” He quotes the whole passage beginning
* * * * * *
Stephen Burroughs does not at all fulfill our preconceived notion of an
habitual criminal. He did not love evil for its own sake. His crimes were
incidental, and he mentions them only as the unfortunate results of
circumstances beyond his own control. His life was rather spent in the
contemplation of virtue. There were some virtues which came easy to
him, and he made the most of them. Like an expert prestidigitator, he kept
the attention fixed on what was irrelevant, so that what was really going
on passed unnoticed. He had eliminated personal responsibility from his
scheme of things, and then proceeded as if nothing were lacking. He had
one invariable measure for right and wrong. That was right which
ministered to his own peace of body and of mind; that was wrong which
did otherwise.
We are coming to see that that imperturbable egotism is the characteristic
of the “criminal mind” that is least susceptible to treatment. Sins of
passion are often repented of as soon as they are committed. Sins of
ignorance are cured by letting in the light. Sins of weakness yield to an
improved environment. But what are you going to do with the man who is
incapable of seeing that he is in the wrong? Treat him with compassion,
and he accepts the kindness as a tribute to his own merits; attempt to
punish him, and he is a martyr; reason with him, and his controversial
ardor is aroused in defense of his favorite thesis.
Sometimes the lover of humanity, after he has tried everything which he
can think of to make an impression on such a character and to bring him
to a realizing sense of social responsibility, becomes utterly discouraged.
He feels tempted to give up trying any longer. In this he is wrong. He
should not allow himself to be discouraged. Something must be done,
even though nobody knows what it is.
But if the lover of humanity should give up for a time and take a rest by
turning his attention to a more hopeful case, I should not be too hard on
him. My Pardoner, I am sure, must have some indulgence for such a
weakness.
A MAN UNDER ENCHANTMENT
Men of science show us how the whole acts upon each part and
each part acts upon the whole. Modern novelists attempt, not always
successfully, to give the impression of the amazing complexity of
actual life, where all sorts of things are going on at the same time.
Whether we look upon it as his limitation or as his good fortune,
Hawthorne adhered to the spinning-wheel rather than the loom. We
see the antique Fates drawing out the thread. A long series of events
follow one another from a single cause.
A part of the power of Hawthorne over our imagination lies in his
singleness of purpose. In “The Marble Faun” we are told, “The
stream of Miriam’s trouble kept its way through this flood of human
life, and neither mingled with it nor was turned aside.”
We are made to see the dark streams that do not mingle nor turn
aside, and we watch their fatal flow.
But is this real, normal life? In such life do not the streams mingle?
Are not evil influences quickly neutralized, as noxious germs die in
the sunshine? No one would more readily acknowledge this than
Hawthorne. He says: “It is not, I apprehend, a healthy kind of mental
occupation to devote ourselves too exclusively to the study of
individual men and women. If the person under examination be one’s
self, the result is pretty certain to be diseased action of the heart
almost before we can snatch a second glance. Or if we take the
freedom to put a friend under the microscope, we thereby insulate
him from many of his true relations, magnify his peculiarities,
inevitably tear him into parts, and of course patch him clumsily
together again. What wonder, then, that we be frightened at such a
monster, which, after all—though we can point to every feature of his
deformity in the real personage—may be said to have been created
mainly by ourselves.”
The critic of Hawthorne could not describe better the limitation of his
stories as pictures of real life. His characters, however clearly
conceived, are insulated from many of their real relations, and their
peculiarities are magnified.
In the preface to “The Scarlet Letter” he says that the tale “wears to
my eye a stern and sombre aspect, too much ungladdened by the
tender and familiar influences which soften almost every scene of
Nature and real life, and which undoubtedly should soften every
picture of them.”
One who would defend Hawthorne the Author against Hawthorne the
Critic must point out the kind of literature to which his work belongs.
When we judge it by the rule of the romance or of the realistic novel,
we fail to do justice to its essential quality. The romancer, the story-
teller pure and simple, is attracted by the swift sequence of events.
His nimble fancy follows a plot as a kitten follows a string. Now it
happens that in a world constituted as ours is the sequence of
events follows a moral order. A good story has always in it an
element of poetic justice. But the romancer does not tell his story for
the sake of the moral. He professes to be as much surprised when it
is discovered as is the most innocent reader. In like manner the
realistic novel, in proportion as it is a faithful portrayal of life, has an
ethical lesson. But the writer disclaims any purpose of teaching it.
His business is to tell what the world is like. He leaves the rest to
your intelligence.
But there is another kind of literature; it is essentially allegory. The
allegorist takes a naked truth and clothes it with the garments of the
imagination. Frequently the clothes do not fit and the poor truth
wanders about awkwardly, self-conscious to the last degree. But if
the artist be a genius the abstract thought becomes a person.
Hawthorne’s work is something more than allegory, but his mind
worked allegorically. His characters were abstract before they
became concrete. He was not a realist aiming to give a
comprehensive survey of the actual world. He consciously selected
the incidents and scenes which would illustrate his theme.
In his conclusion of “The Marble Faun,” when the actors have
withdrawn, the Author comes before the curtain and says that he
designed “the story and the characters to bear, of course, a certain
relation to human nature and human life, but still to be so artfully and
airily removed from our mundane sphere that some laws and
proprieties of their own should be implicitly and insensibly
acknowledged. The idea of the modern Faun, for example, loses all
the poetry and beauty which the Author fancied in it and becomes
nothing better than a grotesque absurdity if we bring it into the actual
light of day.” This is not realism.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com