<bool> = thread.is_alive() <spanclass="hljs-comment"># Checks if thread has finished executing.</span>
thread.join() <spanclass="hljs-comment"># Waits for thread to finish.</span>
<div><h3id="thread">Thread</h3><pre><codeclass="python language-python hljs"><Thread> = Thread(target=<function>) <spanclass="hljs-comment"># Use `args=<collection>` to set arguments.</span>
<Thread>.start() <spanclass="hljs-comment"># Starts the thread.</span>
<bool> = <Thread>.is_alive() <spanclass="hljs-comment"># Checks if thread has finished executing.</span>
<Thread>.join() <spanclass="hljs-comment"># Waits for thread to finish.</span>
</code></pre></div>
<ul>
<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>
<div><h3id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><codeclass="python language-python hljs"><Semaphore> = Semaphore(value=<spanclass="hljs-number">1</span>) <spanclass="hljs-comment"># Lock that can be acquired 'value' times.</span>
<Event> = Event() <spanclass="hljs-comment"># Method wait() blocks until set() is called.</span>
<Barrier> = Barrier(n_times) <spanclass="hljs-comment"># Method wait() blocks until it's called 'n_times'.</span>
<div><h3id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><codeclass="python language-python hljs"><Semaphore> = Semaphore(value=<spanclass="hljs-number">1</span>) <spanclass="hljs-comment"># Lock that can be acquired 'value' times.</span>
<Event> = Event() <spanclass="hljs-comment"># Method wait() blocks until set() is called.</span>
<Barrier> = Barrier(n_times) <spanclass="hljs-comment"># Method wait() blocks until it's called 'n_times'.</span>
</code></pre></div>
<div><h3id="threadpoolexecutor">Thread Pool Executor</h3><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> concurrent.futures <spanclass="hljs-keyword">import</span> ThreadPoolExecutor
<div><h4id="future">Future:</h4><pre><codeclass="python language-python hljs"><bool> = <Future>.done() <spanclass="hljs-comment"># Checks if thread has finished executing.</span>
<obj> = <Future>.result() <spanclass="hljs-comment"># Waits for thread to finish and returns result.</span>
<div><h4id="future">Future:</h4><pre><codeclass="python language-python hljs"><bool> = <Future>.done() <spanclass="hljs-comment"># Checks if thread has finished executing.</span>
<obj> = <Future>.result() <spanclass="hljs-comment"># Waits for thread to finish and returns result.</span>
</code></pre></div>
<div><h3id="queue">Queue</h3><p><strong>A thread-safe FIFO queue. For LIFO queue use LifoQueue.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> queue <spanclass="hljs-keyword">import</span> Queue
@ -1848,10 +1846,10 @@ lock.release()
</code></pre></div>
<pre><codeclass="python language-python hljs"><Queue>.put(<el>) <spanclass="hljs-comment"># Blocks until queue stops being full.</span>
<Queue>.put_nowait(<el>) <spanclass="hljs-comment"># Raises queue.Full exception if full.</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>
<pre><codeclass="python language-python hljs"><Queue>.put(<el>) <spanclass="hljs-comment"># Blocks until queue stops being full.</span>
<Queue>.put_nowait(<el>) <spanclass="hljs-comment"># Raises queue.Full exception if full.</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>
</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