(Ebook) Learning Concurrency in Python by Elliot Forbes ISBN 9781787285378, 1787285375 - The full ebook with all chapters is available for download
(Ebook) Learning Concurrency in Python by Elliot Forbes ISBN 9781787285378, 1787285375 - The full ebook with all chapters is available for download
https://ebooknice.com/product/python-concurrency-with-asyncio-38303740
https://ebooknice.com/product/python-in-practice-create-better-
programs-using-concurrency-libraries-and-patterns-38438370
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
https://ebooknice.com/product/python-machine-learning-machine-
learning-and-deep-learning-with-python-scikit-learn-and-
tensorflow-6868034
(Ebook) Modern Concurrency in Swift by Martin Todorov
https://ebooknice.com/product/modern-concurrency-in-swift-47888402
https://ebooknice.com/product/deep-learning-for-natural-language-
processing-develop-deep-learning-models-for-natural-language-in-
python-11575184
(Ebook) Deep Learning for Finance: Creating Machine & Deep Learning
Models for Trading in Python by Kaabar, Sofien ISBN 9781098148393,
1098148398
https://ebooknice.com/product/deep-learning-for-finance-creating-
machine-deep-learning-models-for-trading-in-python-56363826
(Ebook) Deep Learning for Finance: Creating Machine & Deep Learning
Models for Trading in Python by Sofien Kaabar ISBN 9781098148393,
1098148398
https://ebooknice.com/product/deep-learning-for-finance-creating-
machine-deep-learning-models-for-trading-in-python-54868706
https://ebooknice.com/product/pragmatic-python-programming-learning-
python-the-smart-way-44752148
Learning Concurrency in
Python
4QFFEVQZPVS1ZUIPODPEFXJUIDMFBOSFBEBCMFBOE
BEWBODFEDPODVSSFODZUFDIOJRVFT
Elliot Forbes
BIRMINGHAM - MUMBAI
Learning Concurrency in Python
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be caused
directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
1VCMJTIFECZ1BDLU1VCMJTIJOH-UE
-JWFSZ1MBDF
-JWFSZ4USFFU
#JSNJOHIBN
#1#6,
ISBN 978-1-78728-537-8
XXXQBDLUQVCDPN
Credits
He has worked on numerous different technologies such as GoLang and NodeJS and plain
old Java, and he has spent years working on concurrent enterprise systems. It is with this
experience that he was able to write this book.
Elliot has even worked at Barclays Investment Bank for a summer internship in London and
has maintained a couple of software development websites for the last three years.
About the Reviewer
Nikolaus Gradwohl was born 1976 in Vienna, Austria and always wanted to become an
inventor like Gyro Gearloose. When he got his first Atari, he figured out that being a
computer programmer is the closest he could get to that dream. For a living, he wrote
programs for nearly anything that can be programmed, ranging from an 8-bit
microcontroller to mainframes. In his free time, he likes to master on programming
languages and operating systems.
Nikolaus authored the Processing 2: Creative Coding Hotshot book, and you can see some of
his work on his blog at IUUQXXXMPDBMHVSVOFU.
www.PacktPub.com
For support files and downloads related to your book, please visit XXX1BDLU1VCDPN.
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at XXX1BDLU1VCDPN and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at TFSWJDF!QBDLUQVCDPN for more details.
At XXX1BDLU1VCDPN, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and
eBooks.
IUUQTXXXQBDLUQVCDPNNBQU
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt
books and video courses, as well as industry-leading tools to help you plan your personal
development and advance your career.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial
process. To help us improve, please leave us an honest review on this book's Amazon page
at IUUQTXXXBNB[PODPNEQ.
If you'd like to join our team of regular reviewers, you can e-mail us at
DVTUPNFSSFWJFXT!QBDLUQVCDPN. We award our regular reviewers with free eBooks and
videos in exchange for their valuable feedback. Help us be relentless in improving our
products!
Table of Contents
Preface 1
Chapter 1: Speed It Up! 6
History of concurrency 7
Threads and multithreading 8
What is a thread? 8
Types of threads 9
What is multithreading? 9
Processes 10
Properties of processes 11
Multiprocessing 12
Event-driven programming 13
Turtle 14
Breaking it down 15
Reactive programming 16
ReactiveX - RxPy 16
Breaking it down 18
GPU programming 19
PyCUDA 20
OpenCL 20
Theano 21
The limitations of Python 21
Jython 22
IronPython 23
Why should we use Python? 23
Concurrent image download 23
Sequential download 24
Breaking it down 24
Concurrent download 25
Breaking it down 26
Improving number crunching with multiprocessing 26
Sequential prime factorization 27
Breaking it down 27
Concurrent prime factorization 28
Breaking it down 29
Summary 30
Chapter 2: Parallelize It 31
Understanding concurrency 32
Properties of concurrent systems 32
I/O bottlenecks 33
Understanding parallelism 35
CPU-bound bottlenecks 36
How do they work on a CPU? 36
Single-core CPUs 37
Clock rate 37
Martelli model of scalability 38
Time-sharing - the task scheduler 39
Multi-core processors 40
System architecture styles 41
SISD 41
SIMD 42
MISD 44
MIMD 44
Computer memory architecture styles 45
UMA 45
NUMA 46
Summary 48
Chapter 3: Life of a Thread 49
Threads in Python 49
Thread state 50
State flow chart 51
Python example of thread state 51
Breaking it down 52
Different types of threads 52
POSIX threads 53
Windows threads 53
The ways to start a thread 53
Starting a thread 53
Inheriting from the thread class 54
Breaking it down 54
Forking 55
Example 55
Breaking it down 55
Daemonizing a thread 56
Example 57
Breaking it down 57
[ ii ]
Handling threads in Python 57
Starting loads of threads 58
Example 58
Breaking it down 58
Slowing down programs using threads 59
Example 59
Breaking it down 60
Getting the total number of active threads 61
Example 61
Breaking it down 61
Getting the current thread 62
Example 62
Breaking it down 62
Main thread 63
Example 63
Breaking it down 63
Enumerating all threads 64
Example 64
Breaking it down 64
Identifying threads 65
Example 65
Breakdown 66
Ending a thread 67
Best practice in stopping threads 67
Example 67
Output 68
Orphan processes 68
How does the operating system handle threads 68
Creating processes versus threads 68
Example 69
Breaking it down 69
Multithreading models 70
One-to-one thread mapping 71
Many-to-one 71
Many-to-many 72
Summary 73
Chapter 4: Synchronization between Threads 74
Synchronization between threads 75
The Dining Philosophers 75
Example 77
Output 78
Race conditions 78
Process execution sequence 79
[ iii ]
The solution 80
Critical sections 81
Filesystem 81
Life-critical systems 81
Shared resources and data races 82
The join method 83
Breaking it down 83
Putting it together 84
Locks 84
Example 84
Breaking it down 86
RLocks 86
Example 87
Breaking it down 87
Output 88
RLocks versus regular locks 89
Condition 90
Definition 90
Example 90
Our publisher 90
Our subscriber 91
Kicking it off 92
The results 93
Semaphores 93
Class definition 94
Example 94
The TicketSeller class 94
Output 96
Thread race 96
Bounded semaphores 96
Events 97
Example 98
Breaking it down 98
Barriers 98
Example 99
Breaking it down 99
Output 100
Summary 101
Chapter 5: Communication between Threads 102
Standard data structures 103
Sets 103
Extending the class 103
Exercise - extending other primitives 104
Decorator 104
[ iv ]
Class decorator 105
Lists 106
Queues 107
FIFO queues 107
Example 108
Breaking it down 108
Output 109
LIFO queues 109
Example 110
Breaking it down 111
Output 111
PriorityQueue 112
Example 112
Breakdown 113
Output 114
Queue objects 114
Full/empty queues 114
Example 115
Output 115
The join() function 115
Example 116
Breakdown 117
Output 117
Deque objects 117
Example 117
Breakdown 118
Output 118
Appending elements 119
Example 119
Breaking it down 119
Output 120
Popping elements 120
Example 120
Breaking it down 121
Output 121
Inserting elements 121
Example 122
Breaking it down 122
Output 122
Rotation 122
Example 123
Breaking it down 123
Output 124
Defining your own thread-safe communication structures 124
A web Crawler example 124
Requirements 125
[v]
Design 125
Our Crawler class 125
Our starting point 127
Extending the queue object 129
Breaking it down 129
Output 129
Future enhancements 130
Conclusion 130
Exercise - testing your skills 131
Summary 131
Chapter 6: Debug and Benchmark 132
Testing strategies 133
Why do we test? 133
Testing concurrent software systems 134
What should we test? 134
Unit tests 134
PyUnit 135
Example 135
Output 136
Expanding our test suite 136
Unit testing concurrent code 136
Integration tests 137
Debugging 138
Make it work as a single thread 138
Pdb 139
An interactive example 140
Catching exceptions in child threads 142
Benchmarking 143
The timeit module 144
Timeit versus time 145
Command-line example 145
Importing timeit into your code 145
Utilizing decorators 147
Timing context manager 147
Output 149
Profiling 149
cProfile 149
Simple profile example 150
The line_profiler tool 152
Kernprof 152
Memory profiling 154
Memory profile graphs 155
Summary 158
[ vi ]
Chapter 7: Executors and Pools 159
Concurrent futures 159
Executor objects 160
Creating a ThreadPoolExecutor 160
Example 161
Output 161
Context manager 162
Example 162
Output 163
Maps 163
Example 164
Output 164
Shutdown of executor objects 164
Example 165
Output 165
Future objects 166
Methods in future objects 166
The result() method 166
The add_done_callback() method 167
The .running() method 167
The cancel() method 167
The .exception() method 167
The .done() method 167
Unit testing future objects 168
The set_running_or_notify_cancel() method 168
The set_result() method 168
The set_exception() method 168
Cancelling callable 168
Example 169
Output 170
Getting the result 170
Example 171
Output 172
Using as_completed 172
Example 172
Output 173
Setting callbacks 174
Example 174
Output 175
Chaining callbacks 176
Exception classes 176
Example 176
Output 177
ProcessPoolExecutor 178
Creating a ProcessPoolExecutor 178
[ vii ]
Example 178
Output 179
Context Manager 179
Example 179
Output 180
Exercise 180
Getting started 180
Improving the speed of computationally bound problems 180
Full code sample 181
Output 182
Improving our crawler 183
The plan 183
New improvements 184
Refactoring our code 184
Storing the results in a CSV file 186
Exercise - capture more info from each page crawl 187
concurrent.futures in Python 2.7 188
Summary 188
Chapter 8: Multiprocessing 189
Working around the GIL 189
Utilizing sub-processes 190
Example 190
Output 191
The life of a process 191
Starting a process using fork 191
Spawning a process 192
Forkserver 192
Daemon processes 192
Example 193
Breaking it down 193
Output 193
Identifying processes using PIDs 194
Example 194
Output 195
Terminating a process 196
Example 196
Getting the current process 197
Subclassing processes 197
Example 198
Output 198
Multiprocessing pools 199
[ viii ]
The difference between concurrent.futures.ProcessPoolExecutor and
Pool 199
Context manager 200
Example 200
Output 201
Submitting tasks to a process pool 201
Apply 201
Apply_async 202
Map 203
Map_async 204
Imap 204
Imap_unordered 205
Starmap 206
Starmap_async 207
Maxtasksperchild 207
Communication between processes 208
Pipes 209
Anonymous pipes 209
Named pipes 209
Working with pipes 210
Example 210
Handling Exceptions 211
Using pipes 211
Multiprocessing managers 212
Namespaces 213
Example 213
Queues 214
Example 214
Output 215
Listeners and clients 215
Example 216
The Listener class 216
The Client class 217
Output 217
Logging 218
Example 218
Communicating sequential processes 220
PyCSP 220
Processes in PyCSP 221
Output 221
Summary 222
Chapter 9: Event-Driven Programming 223
Event-driven programming 224
[ ix ]
The event loop 225
Asyncio 226
Getting started 227
Event loops 227
The run_forever() method 227
The run_until_complete() method 228
The stop() method 229
The is_closed() method 229
The close() function 230
Tasks 230
Example 230
The all_tasks(loop=None) method 231
The current_tasks() function 232
The cancel() function 233
Task functions 234
The as_completed(fs, *, loop=None, timeout=None) function 234
The ensure_future(coro_or_future, *, loop=None) function 234
The wrap_future(future, *, loop=None) function 234
The gather(*coroes_or_futures, loop=None, return_exceptions=False) function 235
The wait() function 235
Futures 236
Example 237
Output 237
Coroutines 237
Chaining coroutines 238
Output 241
Transports 241
Protocols 241
Synchronization between coroutines 242
Locks 242
Queues 244
Events and conditions 245
Semaphores and BoundedSemaphores 245
Sub-processes 246
Debugging asyncio programs 246
Debug mode 246
Twisted 248
A simple web server example 248
Gevent 250
Event loops 250
Greenlets 251
Simple example-hostnames 251
Output 252
[x]
Monkey patching 252
Summary 253
Chapter 10: Reactive Programming 254
Basic reactive programming 255
Maintaining purity 255
ReactiveX, or RX 255
Installing RxPY 256
Observables 257
Creating observers 257
Example 257
Example 2 259
Breaking it down 259
Output 260
Lambda functions 260
Example 261
Breaking it down 261
On_next, on_completed, and on_error in lambda form 262
Output 263
Operators and chaining 263
Filter example 263
Breaking it down 264
Chained operators 264
The different operators 265
Creating observables 265
Transforming observables 265
Filtering observables 266
Error-handling observables 266
Hot and cold observables 266
Emitting events 267
Example 267
Breaking it down 268
Output 268
Multicasting 268
Example 269
Output 270
Combining observables 271
Zip() example 271
Output 272
The merge_all() operator 272
Output 273
Concurrency 273
Example 274
Output 275
PyFunctional 276
[ xi ]
Installation and official docs 276
Simple example 277
Output 277
Streams, transformations, and actions 277
Filtering lists 278
Output 279
Reading/writing SQLite3 279
Compressed files 280
Parallel execution 281
Summary 282
Chapter 11: Using the GPU 283
Introduction to GPUs 284
Why use the GPU? 285
Data science 285
Branches of data science 286
Machine learning 286
Classification 286
Cluster analysis 286
Data mining 287
CUDA 288
Working with CUDA without a NVIDIA graphics card 289
PyCUDA 289
Features 290
Simple example 290
Kernels 291
GPU arrays 292
Numba 292
Overview 293
Features of Numba 293
LLVM 293
Cross-hardware compatibility 294
Python compilation space 294
Just-in-Time (JiT) versus Ahead-of-Time (Aot) compilation 295
The Numba process 295
Anaconda 296
Writing basic Numba Python programs 296
Compilation options 297
nopython 297
nogil 297
The cache option 298
The parallel option 298
Issues with Numba 298
[ xii ]
Random documents with unrelated
content Scribd suggests to you:
The League’s rule in assigning cases, indeed, is to choose as
investigator the man whose social, professional, or business
connections are such that he can “clean up” with the least effort and
in the shortest space of time. When there are many places to visit,
the case goes to a man owning a motor car. If it is complex in
character, with lines extending into various industries, clubs, trades,
and so on, the work may be divided and several members assigned
to it. The main idea is to get the work done, and done quickly—the
secondary purpose to make it as easy as may be for the members.
League members knew little about methods of investigation. But
they had that priceless gift, intelligence, and they learned by doing.
There was such a mass of complaints, tips, and wild guesses
concerning enemy activities waiting to be handled, that no extensive
schooling could be attempted. The cleverest government operatives
available and experienced city and private detectives talked to
groups of captains and lieutenants, and these passed along the
information to their men. A. Bruce Bielaski, Chief of the Bureau of
Investigation, Department of Justice, was quick to recognize the
possibilities of the League. Everywhere his organization gave
invaluable aid and coöperation in training League members.
Able lawyers made brief but comprehensive digests of the laws
involved and the rules of evidence to be observed. Methods of work
and problems of authority and conduct were explained at length in a
handbook. Supplementing the handbook and the law digest,
bulletins were published at intervals to suggest better methods, to
report fresh evidence of German plans and propaganda, or to sum
up and interpret the new laws which Congress was enacting for the
punishment of espionage and sedition.
Close touch was kept at every step with the Department of
Justice. Forms for reports and records were adopted, conforming to
the system in use by the Department. Carbons of all reports and
records were made for the files of the Bureau of Investigation.
Eventually a complete record of each case found its way to the
master file in Washington. In this way duplication of effort was
avoided, complete coöperation assured, and the exact status of any
inquiry could be learned in a moment by any one needing the
information.
Far from running wild in its enthusiasm to corral all enemy agents,
the League tried to give every alien it investigated an American
square deal. Perhaps the finest paragraph in the handbook is this
one urging the right of aliens to considerate treatment until their
unfriendly attitude is revealed:
“Many aliens resident in this country are absolutely loyal to its
institutions and its laws, and many individuals having the legal status
of alien enemies are not only conducting themselves with due
respect to our laws, but are of great value in industry and business.
Great care must be exercised by members to avoid unnecessary
alarm to aliens and to avoid causing apprehension upon their part as
to the fairness and justice of the attitude of the Government toward
them. In this regard members will be called upon for the exercise of
judgment and discretion of a high order. They should protect citizens
and aliens from unjust suspicion, but must fearlessly ascertain and
report treason and disloyalty wherever found.”
All this has to do with the investigation of specific cases after they
have been brought to the League’s attention by the report of a
member, an outside complaint, or a request from the Department of
Justice for an inquiry into the facts. Quite as important in
discouraging disloyalty or pro-German activities is the service of
League members as eyes and ears for the Government in detecting
and making first reports on offenses or intended offenses against the
war code of the United States.
This means that every League member is always on the lookout
for any word or act that smacks of sedition or espionage. It is here
that the classified organization by industries, trades, professions,
and individual business establishments develops its full value. When
a factory making munitions, clothing, motor trucks, or any other war
necessity has been organized as a League unit, the members are on
the alert for signs of disturbance. They can quickly report to their
supervisor what they have seen or heard, and, after comparing
notes, can take precautions against the threatened trouble. If they
need outside help in checking up a suspect after working hours, the
territorial organization is ready to coöperate. The suspect need never
know that he is under suspicion until his guilt or innocence is pretty
well established.
Such a factory unit is typical of the League organization in the
larger cities. Besides the strictly industrial group, there are usually
eight broad divisions, any one of which may be important enough to
have an assistant bureau chief, and several captains, lieutenants,
and individual units. These divisions take in the real estate, financial,
insurance, and professional groups, the hotels, transportation
companies, public utilities, and merchandising interests—wholesale,
retail, and mail-order. And the industries alone may be numerous
and powerful enough to call for separate divisions—munitions,
packers’ products, food stuffs, war equipment, metal trades, lumber,
motor cars, electrical machinery and supplies, chemicals and paints,
and so on. It all depends on how numerous and how large are the
establishments in each line. Outside the larger cities territorial
organization is the rule. When the district is identified with some
industry of special value in war, like mining, lumbering, or cattle
raising, protection of that industry may be the chief function of the
League.
Not only does the classified method of organization help each
trade and profession to police itself; it greatly facilitates important
inquiries. For example, suppose that the Government wants to find
and learn the local errand of a visiting electrical engineer with a
German name and considerable cash whom it has had under
surveillance elsewhere. On being asked for a report, the League’s
local Chief assigns the case to one of his deputies. The latter notifies
the supervisors of the various hotel units to watch out for the
stranger, report his arrival, and keep watch of his letters and
telephone calls. He also communicates with the head of the
professional division and asks that an electrical engineer be detailed
on the case.
When the suspect has been located and the hotel supervisor has
transmitted any other information he has been able to get, the
engineer member begins work. Going to the hotel he finds or makes
a way to become acquainted with the stranger, offers him the usual
professional courtesies, and gives him a chance to suggest why he is
in town or whom he wants to see. Direct questions are not asked, of
course, since they would put the stranger on his guard. After he has
carried the inquiry as far as he can, the engineer member quietly
and casually goes his way, unless the stranger has accepted his
offers of help or hospitality.
If the suspect has “covered up” more than an honest engineer
should, he is systematically shadowed by other League operatives
during the remainder of his stay. Walking out or staying in his room,
travelling in taxicabs or in street cars, making business calls or social
calls, one or more of his two “shadows” would probably keep him in
sight and make memoranda regarding every person he met and
spoke with and every significant circumstance that took place. Only
when in a private house or in his hotel room would he escape
observation—and even then a fairly close tab would be kept on what
he was doing.
A record would be made of every telephone call, every telegram,
every letter received, with particular reference to the postmark,
dates, and the return cards on the envelopes. His baggage would be
inventoried and described, even to its hotel labels, its character, and
its probable price and origin. When he finally departed, if the porter
bought his tickets for him or whether he purchased them himself at
the station, his route, and his first destination—all would be matters
of history. One of his “shadows” would even see him safely past the
last suburban stop from which he might double back to the city or to
a waiting confederate.
This seems a mighty pother to make about an apparently innocent
traveller. But the League prefers to work overtime and play safe. The
narratives of some of the “tailings” would make marvellous reading if
they only led up to the proper dramatic climax. Many of them do—
but those are not to be talked about yet awhile. And the others are
significant only because they are the records of uninteresting tasks
as faithfully executed as though the sheltering doorway or hotel
lobby chair were a listening post in France.
Remember that these tasks were made both complex and difficult
by the lack of laws defining espionage, disloyalty, and sedition as
punishable crimes. That ancient act of 1798 could be invoked for the
internment of dangerous enemy aliens. But an American citizen,
native or naturalized, could spit treason and plot trouble unchecked
so long as he did not run foul of the civil or the criminal code. That
is all changed now; the amended Espionage and Sedition Law,
signed by the President in June, 1917, is so broad and has such a
fine set of serviceable teeth that no disloyal citizen or unfriendly
alien can escape the penalty if his guilt can be proved.
For more than a year, however, the League was compelled not
only to prove a citizen’s pro-German activities; it had also to find a
way to punish them, or at least to discourage them. Every inquiry
into such a case, therefore, had to be supplemented by an effort to
find evidence of an offense against the civil or criminal statutes. And
where this failed, a good old-fashioned “talking to” often had the
desired effect.
Hatred of “Prussian militarism” and pretended allegiance to the
United States were the favourite pose of many propagandists whom
the League rounded up and secured billets for in various internment
camps. Most of these had taken out their first naturalization papers;
except in a few middle and western states like Nebraska, where
“first papers” and six months of residence confer the right to vote,
this was no protection when evidence of disloyalty or pro-German
activity was adduced against them.
Typical of this class was the case of an Austrian officer of reserves
who was six months under investigation before he was arrested. Like
so many other interned Teutons, his entry into the United States had
been by way of the Argentine. Traced back, it was discovered that
he had reported to the Austrian Consul in Buenos Aires as an officer
of reserves at the first mobilization call, July 27, 1914; and again
when he sailed for the United States with a false Swedish passport in
1915. Then, in succession, he had registered at the San Francisco,
St. Louis, and Chicago consulates—at the last on September 30,
1915.
In less than six months, however, he had applied for naturalization
papers and was arranging to return to Buenos Aires as selling agent
for several American houses. When the State Department denied
him a passport, he devised another means of keeping watch of
American efforts to supplant German houses in the South American
markets. This was an export information bureau, but his information
was not live enough to hold his clients long. Next he projected a
$2,000,000 corporation to take over and operate the German
interned steamships at New York. By turns also he was advertising
solicitor and automobile salesman.
The occupation he followed always allowed him maximum
freedom in moving about and a plausible excuse for approaching
almost any one he wanted to reach. Very early in the inquiry, his
defenselessness appeared; he had entered the country under a false
passport and could be arrested whenever the Department of Justice
chose to move. Because he had arrived in San Francisco eighteen
months before our declaration of war, he was given the benefit of
the doubt. Not until his character as a dangerous enemy alien had
been established was he interned. He will be deported at the end of
the war.
Different in detail, but similar in character and outcome, was the
Odyssey of a missionary of German culture, whose earnings were as
nominal as his expenditures were excessive. Arriving in New York in
1912, also by way of the Argentine, he had spent the intervening
time travelling about the country in various rôles which would bring
him in contact with rich Americans of German birth or blood. At
various times he was a dealer in pictures, in stocks and bonds, and
in subscription editions of the German classics.
As a side line, he seems to have been checking up American
efforts to develop sources of potash, Germany’s one great monopoly
in minerals. He even engaged himself as stock salesman for an
Eastern company organized to extract potash from the Pacific kelp
fields and made at least one trip to the coast to study that new
industry. Always his scale of living was far in excess of his earnings
from such sources of income as could be traced. After a long and
patient inquiry—covering nearly eight months from the time the
man’s pro-German utterances were first reported—he was finally
interned for the duration of the war.
Enemy aliens have not been alone in keeping League members up
at night. Far more numerous have been the investigations bearing
upon the character and loyalty of American citizens, particularly
candidates for commissions in the Army and Navy and applicants for
civilian service in positions of trust. Still a third class of inquiries
which have lacked the thrill of espionage cases have been the
thousands of investigations made of claims for exemption or
deferred classification under the selective service law.
Anything like a divided allegiance, of course, would destroy the
usefulness of an army or naval officer—if, indeed, it did not make
him a positive menace to his country. Every character and loyalty
inquiry, therefore, has this background of danger, especially when
the subject is of German or of Austrian ancestry. And sometimes the
League operative must have a keen scent for significant minor
details to detect the danger signal.
For instance, one of the candidates for a recent special officers’
training camp was a young Cincinnati man with a German name. He
was a citizen, of draft age, of such intelligence, experience, and
physique that his acceptance was a foregone conclusion if his loyalty
were assured. Investigation showed him to have been pro-German
in his sympathies before our declaration of war, and practically silent
on war subjects since. His attitude was correct; and his application
for training was a positive count in his favour. But the League
investigator, digging around for information, learned that his man
had been a contributor to a fund raised by a Gaelic newspaper for
the defence of Sir Roger Casement, when that famous Irish rebel
was on trial in London.
If the man had been of Irish blood, such a contribution would
have had little significance; natural sympathy for a compatriot in
trouble might have prompted it. Such an act by a German or an
American, however, suggested more than a passing interest in the
violent pro-German, anti-English propaganda which this particular
weekly exploited. Verifying the story by reference to the files of the
newspaper, the investigator called attention to the fact in his report,
and gave it as his opinion that the candidate wanted a commission
to escape the draft and that he lacked the whole-hearted loyalty and
enthusiasm an Army officer must have to be successful. And, as the
final decision coincided with the investigator’s, the application was
refused.
Another incident—double-barrelled in its effect—has also its
humorous side. One of the Chicago League officials picked up two
deserters on Michigan Avenue early one evening last December.
Neither had an overcoat, one had evidently “hocked” his blouse to
provide food or drink. The League man knew he must turn them
over to the police, but the boys were so cold and wretched that he
determined to give them a good dinner before surrendering them.
At his club, his “guests” created a certain amount of stir—and
seemed to enjoy it. They “didn’t miss a station from soup to
cigarettes,” as one of them expressed it. They were finishing up
when a young man in a captain’s uniform came over and interjected
himself into the feast.
“Excuse me,” he began as the host arose, “may I ask what your
interest in these men is?”
His tone was a shade too crisp, even for so young a captain.
“May I ask yours?” the League man countered.
“I’m in command of the provost guard in Chicago,” the other
declared. “It’s my business to look after deserters.”
It was a fatal bit of brag. The League man knew the provost
marshal—knew this fellow was an imposter. But one job at a time.
“I know these chaps and I’m looking after them,” he answered.
“Come along, boys.” And they departed in the olive splendour of a
taxicab. Then it pulled up a little later before a red light, and a
policeman opened the door. The lads were crestfallen but game.
“It was bully while it lasted,” they declared. “Anyway, they’d have
got us sooner or later.”
Before noon next day the youthful pseudo-captain was wiping his
tears away and explaining why he had been impersonating an
officer. There was a group of musical comedy girls in the foreground
and a trail of forged checks and unpaid club and hotel bills in the
background. He is learning in Leavenworth prison, now, that the
lion’s skin is dangerous apparel and that discretion is the better part
of a masquerade.
The League files are crammed with reports which have blacker
themes—or the scarlet motive which stands for constructive treason.
There are folders that deal with reported graft in the purchase of
materials for Army camps and subsequent fires which covered up
the scanting of buildings. There are others on cases of undue
influence brought to bear on members of exemption boards; and
sickening instances of “quacks” who have ruined strong but cowardly
young bodies for blood money. There are tales of extortion by
shyster lawyers for filling out questionnaires—and other tales of
money paid by enemy aliens to disreputable “fixers” for pretended
protection against the draft.
The mere classified index of the master file at Washington
intrigues the imagination. Just a glance at the main “guides” will
indicate the range:
Enemy aliens
Unfriendly neutrals
“First-paper” aliens
Disloyal citizens
Pro-German “radicals”
Native-born
Naturalized
Disloyal Government employees
Possible spies or German agents
Pro-German applicants for Government positions
Citizens or aliens living in luxury without visible sources of income
Suspicious foreigners
Enemy propaganda
(Twenty sub-heads here)
Enemy alien funds
Alien extortion cases
I. W. W. agitators
Check of jury panels to keep out pro-Germans
Incendiary fires in war-material plants
Wireless stations
Bomb and dynamite cases
Passport applicants
Seditious utterances
Seditious publications
Seditious meetings
Anti-military activities
Organizations to resist draft
Attempted draft evasions
False exemption claims
Physical disability
Dependent relatives
Desertion of wife to enlist in Army
Fraudulent claims of marriage
Army deserters
Impersonation of officers
Sale of liquor to soldiers and sailors
Sale of narcotics to men in service
Hotel surveillance of doubtful transients
Liberty Bond and Red Cross slackers
Theft of Red Cross supplies
Hoarding of foods
Destruction of foods
Character and loyalty of applicants for commissions
In making these investigations the League has coöperated, not
only with the Department of Justice, but also with Army Intelligence,
Navy Intelligence, the Alien Property Custodian, the Food
Administration, the Shipping Board, the Red Cross, the Y. M. C. A.,
and with various other offices at Washington.
The number and variety of cases handled have not constituted the
major service of the League, however. Rather, it has been the
character and intelligence of the membership—the ability to enter
and comb any social, professional, or business circle for information
without betraying that an inquiry was afoot. From this angle alone
the original idea was pretty close to an inspiration, since it
improvised in the hour of need such an organization as not even a
generation of effort and many million dollars could have built up.
Just because it was improvised and its personnel kept secret, the
League could meet the most dangerous German agents on their own
ground and paralyze their efforts by keeping them guessing.
Propaganda dies on the lips of the man who can’t be certain that his
listener is not making mental notes for an official report of the
conversation. And the most subtle scheme of spying or sabotage is
bound to drag when the plot master is harassed by doubts of the
native-born or naturalized accomplices he must enlist for its
execution.
One instance to show how much a local organization must depend
upon its specialists. Last summer it became necessary to know
beyond question whether or not a prominent young German-
American in a seaboard city was supplying the funds for the local
agitation against the draft. Suspicion attached to him because he
spent many evenings aboard his fast-racing schooner in the yacht
club harbour, and could not be induced, in any polite and casual way,
to invite any of the League’s yachting members aboard. His crew,
two Scandinavians, were as voluble as oysters.
The schooner was being tuned up for the annual club cruise late
in July. Two extra sailors would be needed for the race. The League
provided one of them. An upstanding young American, too young for
the first officers’ training camp but in line for the second, was taken
into the League, carefully coached, and turned loose in the harbour
with a loaned cat-boat to impress the German-American skipper with
his sailing skill. The boy finessed his approach successfully and was
asked to train with the crew. But he found nothing material to report
until the schooner had actually won the big race.
That night after the victory had been celebrated in a flood of
champagne, which he alone avoided, he quietly went through all the
private papers in the owner’s cabin, made notes, or copied all that
referred in any way to pro-German activities and returned by rail to
the home port next morning. It turned out that the owner had been
guilty of no real disloyalty, though he had skirted the edge more
than once; but his papers pointed straight to the real source of the
propaganda and the latter was speedily apprehended.
Another interesting case was that of a noted pro-German “pacifist”
who for months was kept under surveillance without evidence being
secured which would bring a conviction under the existing law. He
had declared again and again that nine out of ten Americans were
opposed to the war; that thousands of armed men in Arizona, New
Mexico, and western Texas were only waiting for the signal to rise
against the Government; that another thousand in New York City
were watching for the same signal and a leader. He even intimated
that he had been asked to be that leader. And though the League
could account for every hour of his time, knew every citizen and
Congressman he had conferred with and most of the folk he had
written to, it was December before an indictment could be secured
against him.
That this man is still at liberty, on bail, until the courts reach the
hearing of his case is only a detail. The compensating facts are that
he served the League for some time as a stalking horse for other
citizens and aliens of doubtful loyalty—that ultimately the close
watch on him cut down his activities—and that under the amended
espionage law any one of a hundred things he did or said would land
him quickly in a Federal prison.
In the application of the Selective Service Act the League has
taken off the shoulders of the Government one of its heaviest and
most important tasks. The draft was and is a favoured field of
German agents, who have played upon ignorance and prejudice,
religious and union labour fears, racial antipathies, and the baser
emotions of cupidity and cowardice. They have utilized every device
to persuade men to avoid their military obligations to the country. To
the League is assigned the task of checking up all claims for
exemptions and all failures to appear before exemption boards. This
work, especially in the cities, has entailed enormous labour.
Space forbids a complete review of the League, but at least a
paragraph may be inserted about its organization, which is a model
of simplicity and flexibility. The League creates and is responsible for
its own organization in all of its branches. Executive control of the
organization is centred in a Board of National Directors operating
from National Headquarters at Washington, D. C., in coöperation
with the Attorney-General and the officials of the Bureau of
Investigation of the Department of Justice, and through the latter
with other departments and agencies of the Government.
In each local office the chief is supreme. He investigates his own
men, invites them to join, and directs their work. As already stated,
there is a double organization of the local field—a classified
organization of trades, professions, industries, hotels, large
individual establishments, and office buildings; and a Bureau of
Investigation whose organization is territorial. Uniform blanks for
reports and records are made up after models supplied by national
headquarters, and uniform methods of making investigations are
adopted. This simple plan allows each local organization to select the
types of men that best suit its needs and to adapt itself entirely to
local conditions, while maintaining at the same time complete touch
and coöperation with other communities, with the national
organization, and with the Government.
The success of the League is attested by Attorney-General
Thomas W. Gregory himself. In his annual report to the Congress of
the United States he said of the League: “It has proved to be
invaluable and constitutes a most important auxiliary and reserve
force for the Bureau of Investigation.... This organization has been
of the greatest possible aid in thousands of cases.... Its work has
been performed in a thoroughly commendable manner with a
minimum of friction and complaint and with motives of the highest
patriotism. It is a self-supporting organization, and it would be
difficult to exaggerate the value of its service to the United States
Department of Justice.”
CHAPTER X
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.
ebooknice.com