<Futr> = <Exec>.submit(<func>, <arg_1>, ...) # Creates a thread and returns its Future obj.
<Exec>.shutdown(wait=True) # Blocks until all threads finish executing.
<Exec>.shutdown() # Blocks until all threads finish executing.
```
```python
<bool> = <Future>.done() # Checks if the thread has finished executing.
<obj> = <Future>.result(timeout=None) # Waits for thread to finish and returns result.
<bool> = <Future>.cancel() # Returns False if thread is already running.
<bool> = <Future>.cancel() # Cancels or returns False if running/finished.
<iter> = as_completed(<coll_of_Futures>) # Each Future is yielded as it completes.
```
* **Map() and as_completed() also accept 'timeout' argument that causes TimeoutError if result isn't available in 'timeout' seconds after next() is called.**
@ -2159,13 +2159,13 @@ Operator
**Module of functions that provide the functionality of operators. Functions are ordered by operator precedence, starting with least binding.**
```python
import operator as op
<bool> = op.not_(<obj>) # or, and (both missing), not
<bool> = op.eq/ne/lt/le/gt/ge/contains/is_(<obj>, <obj>) # ==, !=, <, <=, >, >=, in, is
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'kwargs=<dict>'</span></code> to pass keyword arguments to the function.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'daemon=True'</span></code>, or the program will not be able to exit while the thread is alive.</strong></li>
<li><strong>To delay thread execution use <codeclass="python hljs"><spanclass="hljs-string">'Timer(<float>, <func>)'</span></code> instead of Thread().</strong></li>
<li><strong>To delay thread execution use <codeclass="python hljs"><spanclass="hljs-string">'Timer(seconds, <func>)'</span></code> instead of Thread().</strong></li>
</ul>
<div><h3id="lock">Lock</h3><pre><codeclass="python language-python hljs"><lock> = RLock() <spanclass="hljs-comment"># Lock that can only be released by acquirer.</span>
<lock>.acquire() <spanclass="hljs-comment"># Waits for the lock to be available.</span>
<Futr> = <Exec>.submit(<func>, <arg_1>, ...) <spanclass="hljs-comment"># Creates a thread and returns its Future obj.</span>
<Exec>.shutdown(wait=<spanclass="hljs-keyword">True</span>)<spanclass="hljs-comment"># Blocks until all threads finish executing.</span>
<Exec>.shutdown() <spanclass="hljs-comment"># Blocks until all threads finish executing.</span>
</code></pre></div>
<pre><codeclass="python language-python hljs"><bool> = <Future>.done() <spanclass="hljs-comment"># Checks if the thread has finished executing.</span>
<obj> = <Future>.result(timeout=<spanclass="hljs-keyword">None</span>) <spanclass="hljs-comment"># Waits for thread to finish and returns result.</span>
<bool> = <Future>.cancel() <spanclass="hljs-comment"># Returns False if thread is already running.</span>
<bool> = <Future>.cancel() <spanclass="hljs-comment"># Cancels or returns False if running/finished.</span>
<iter> = as_completed(<coll_of_Futures>) <spanclass="hljs-comment"># Each Future is yielded as it completes.</span>
<li><strong>ProcessPoolExecutor provides true parallelism, but everything sent to/from workers must be <ahref="#pickle">pickable</a>. Queues must be sent using executor's 'initargs' and 'initializer' parameters.</strong></li>
</ul>
<div><h2id="operator"><ahref="#operator"name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators. Functions are ordered by operator precedence, starting with least binding.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> operator <spanclass="hljs-keyword">as</span> op
<bool> = op.not_(<obj>) <spanclass="hljs-comment"># or, and (both missing), not</span>
<div><h4id="addsnoisetoamonowavfile">Adds noise to a mono WAV file:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> random <spanclass="hljs-keyword">import</span> random
<div><h4id="addsnoisetothemonowavfile">Adds noise to the mono WAV file:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> random <spanclass="hljs-keyword">import</span> random
<Surf> = <Font>.render(text, antialias, color) <spanclass="hljs-comment"># Background color can be specified at the end.</span>
</code></pre></div>
<div><h3id="sound">Sound</h3><pre><codeclass="python language-python hljs"><Sound> = pg.mixer.Sound(<path/file/bytes>) <spanclass="hljs-comment"># Loads WAV file or array of signed shorts.</span>
<div><h3id="sound">Sound</h3><pre><codeclass="python language-python hljs"><Sound> = pg.mixer.Sound(<path/file/bytes>) <spanclass="hljs-comment"># WAV file or bytes/array of signed shorts.</span>
<Sound>.play/stop() <spanclass="hljs-comment"># Also <Sound>.set_volume(<float>).</span>