@ -2107,7 +2107,9 @@ with <lock>: # Enters the block by calling acq
```
```
### Thread Pool Executor
### Thread Pool Executor
**Object that manages thread execution.**
* **Object that manages thread execution.**
* **An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be [pickable](#pickle).**
```python
```python
<Exec> = ThreadPoolExecutor(max_workers=None) # Or: `with ThreadPoolExecutor() as <name>: …`
<Exec> = ThreadPoolExecutor(max_workers=None) # Or: `with ThreadPoolExecutor() as <name>: …`
<Exec>.shutdown(wait=True) # Blocks until all threads finish executing.
<Exec>.shutdown(wait=True) # Blocks until all threads finish executing.
@ -2139,24 +2141,23 @@ Operator
--------
--------
**Module of functions that provide the functionality of operators.**
**Module of functions that provide the functionality of operators.**
* **Binary operators require objects to have and(), or(), xor() and invert() special methods, unlike logical operators that work on all types of objects.**
<li><strong>A function has its default values evaluated when it's first encountered in the scope.</strong></li>
<li><strong>A function has its default values evaluated when it's first encountered in the scope.</strong></li>
<li><strong>Any changes to mutable objects will persist between invocations.</strong></li>
<li><strong>Any changes to default values that are mutable will persist between invocations.</strong></li>
</ul>
</ul>
<div><h2id="splatoperator"><ahref="#splatoperator"name="splatoperator">#</a>Splat Operator</h2><div><h3id="insidefunctioncall-1">Inside Function Call</h3><p><strong>Splat expands a collection into positional arguments, while splatty-splat expands a dictionary into keyword arguments.</strong></p><pre><codeclass="python language-python hljs">args = (<spanclass="hljs-number">1</span>, <spanclass="hljs-number">2</span>)
<div><h2id="splatoperator"><ahref="#splatoperator"name="splatoperator">#</a>Splat Operator</h2><div><h3id="insidefunctioncall-1">Inside Function Call</h3><p><strong>Splat expands a collection into positional arguments, while splatty-splat expands a dictionary into keyword arguments.</strong></p><pre><codeclass="python language-python hljs">args = (<spanclass="hljs-number">1</span>, <spanclass="hljs-number">2</span>)
<Barrier> = Barrier(n_times) <spanclass="hljs-comment"># Wait() blocks until it's called n_times.</span>
<Barrier> = Barrier(n_times) <spanclass="hljs-comment"># Wait() blocks until it's called n_times.</span>
</code></pre></div>
</code></pre></div>
<div><h3id="threadpoolexecutor">Thread Pool Executor</h3><p><strong>Object that manages thread execution.</strong></p><pre><codeclass="python language-python hljs"><Exec> = ThreadPoolExecutor(max_workers=<spanclass="hljs-keyword">None</span>) <spanclass="hljs-comment"># Or: `with ThreadPoolExecutor() as <name>: …`</span>
<div><h3id="threadpoolexecutor">Thread Pool Executor</h3><ul>
<li><strong>Object that manages thread execution.</strong></li>
<li><strong>An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be <ahref="#pickle">pickable</a>.</strong></li>
<el> = <Queue>.get() <spanclass="hljs-comment"># Blocks until queue stops being empty.</span>
<el> = <Queue>.get() <spanclass="hljs-comment"># Blocks until queue stops being empty.</span>
<el> = <Queue>.get_nowait() <spanclass="hljs-comment"># Raises queue.Empty exception if empty.</span>
<el> = <Queue>.get_nowait() <spanclass="hljs-comment"># Raises queue.Empty exception if empty.</span>
</code></pre>
</code></pre>
<div><h2id="operator"><ahref="#operator"name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> operator <spanclass="hljs-keyword">import</span> add, sub, mul, truediv, floordiv, mod, pow, neg, abs
<spanclass="hljs-keyword">from</span> operator <spanclass="hljs-keyword">import</span> eq, ne, lt, le, gt, ge
<div><h2id="operator"><ahref="#operator"name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> operator <spanclass="hljs-keyword">as</span> op
<li><strong>Binary operators require objects to have and(), or(), xor() and invert() special methods, unlike logical operators that work on all types of objects.</strong></li>
<div><h2id="introspection"><ahref="#introspection"name="introspection">#</a>Introspection</h2><p><strong>Inspecting code at runtime.</strong></p><div><h3id="variables">Variables</h3><pre><codeclass="python language-python hljs"><list> = dir() <spanclass="hljs-comment"># Names of local variables (incl. functions).</span>
<div><h2id="introspection"><ahref="#introspection"name="introspection">#</a>Introspection</h2><p><strong>Inspecting code at runtime.</strong></p><div><h3id="variables">Variables</h3><pre><codeclass="python language-python hljs"><list> = dir() <spanclass="hljs-comment"># Names of local variables (incl. functions).</span>
<dict> = vars() <spanclass="hljs-comment"># Dict of local variables. Also locals().</span>
<dict> = vars() <spanclass="hljs-comment"># Dict of local variables. Also locals().</span>
<div><h2id="profiling"><ahref="#profiling"name="profiling">#</a>Profiling</h2><div><h3id="stopwatch">Stopwatch</h3><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> time <spanclass="hljs-keyword">import</span> time
<div><h2id="profiling"><ahref="#profiling"name="profiling">#</a>Profiling</h2><div><h3id="stopwatch">Stopwatch</h3><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> time <spanclass="hljs-keyword">import</span> time
'<strong>Objects returned by the <a href="#itertools">itertools</a> module, such as count, repeat and cycle.</strong>':'<strong>Objects returned by the itertools module, such as count, repeat and cycle (p. 3).</strong>',
'<strong>Objects returned by the <a href="#itertools">itertools</a> module, such as count, repeat and cycle.</strong>':'<strong>Objects returned by the itertools module, such as count, repeat and cycle (p. 3).</strong>',
'<strong>Generators returned by the <a href="#generator">generator functions</a> and <a href="#comprehensions">generator expressions</a>.</strong>':'<strong>Generators returned by the generator functions (p. 4) and generator expressions (p. 11).</strong>',
'<strong>Generators returned by the <a href="#generator">generator functions</a> and <a href="#comprehensions">generator expressions</a>.</strong>':'<strong>Generators returned by the generator functions (p. 4) and generator expressions (p. 11).</strong>',
'<strong>File objects returned by the <a href="#open">open()</a> function, etc.</strong>':'<strong>File objects returned by the open() function (p. 22), etc.</strong>',
'<strong>File objects returned by the <a href="#open">open()</a> function, etc.</strong>':'<strong>File objects returned by the open() function (p. 22), etc.</strong>',
'<strong>Another solution in this particular case is to use functions and_() and or_() from the module <a href="#operator">operator</a>.</strong>':'<strong>Another solution in this particular case is to use functions and_() and or_() from the module \'operator\' (p. 31).</strong>',
'<strong>Functions report OS related errors by raising either OSError or one of its <a href="#exceptions-1">subclasses</a>.</strong>':'<strong>Functions report OS related errors by raising OSError or one of its subclasses (p. 23).</strong>',
'<strong>Functions report OS related errors by raising either OSError or one of its <a href="#exceptions-1">subclasses</a>.</strong>':'<strong>Functions report OS related errors by raising OSError or one of its subclasses (p. 23).</strong>',
'<strong>Bools will be stored and returned as ints and dates as <a href="#encode">ISO formatted strings</a>.</strong>':'<strong>Bools will be stored and returned as ints and dates as ISO formatted strings (p. 9).</strong>',
'<strong>Bools will be stored and returned as ints and dates as <a href="#encode">ISO formatted strings</a>.</strong>':'<strong>Bools will be stored and returned as ints and dates as ISO formatted strings (p. 9).</strong>',
'<strong>An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be <a href="#pickle">pickable</a>.</strong>':'<strong>An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be pickable (p. 25).</strong>',
'<strong>Asyncio module also provides its own <a href="#queue">Queue</a>, <a href="#semaphoreeventbarrier">Event</a>, <a href="#lock">Lock</a> and <a href="#semaphore-event-barrier">Semaphore</a> classes.</strong>':'<strong>Asyncio module also provides its own Queue, Event, Lock and Semaphore classes (p. 30).</strong>',
'<strong>Asyncio module also provides its own <a href="#queue">Queue</a>, <a href="#semaphoreeventbarrier">Event</a>, <a href="#lock">Lock</a> and <a href="#semaphore-event-barrier">Semaphore</a> classes.</strong>':'<strong>Asyncio module also provides its own Queue, Event, Lock and Semaphore classes (p. 30).</strong>',