Skip to content

Commit 84ae7a3

Browse files
committed
Threading
1 parent f36d1a9 commit 84ae7a3

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,12 +2043,13 @@ with lock:
20432043
### Thread Pool Executor
20442044
```python
20452045
from concurrent.futures import ThreadPoolExecutor
2046-
with ThreadPoolExecutor(max_workers=None) as executor:
2046+
with ThreadPoolExecutor(max_workers=None) as executor: # None == `n_cores * 5`.
20472047
<iter> = executor.map(lambda x: x + 1, range(3)) # (1, 2, 3)
20482048
<iter> = executor.map(lambda x, y: x + y, 'abc', '123') # ('a1', 'b2', 'c3')
20492049
<Future> = executor.submit(<function> [, <arg_1>, ...])
20502050
```
20512051

2052+
#### Future
20522053
```python
20532054
<bool> = <Future>.done() # Checks if thread has finished executing.
20542055
<obj> = <Future>.result() # Waits for thread to finish and returns result.

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,15 +1799,16 @@
17991799
</code></pre></div>
18001800

18011801
<div><h3 id="threadpoolexecutor">Thread Pool Executor</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> concurrent.futures <span class="hljs-keyword">import</span> ThreadPoolExecutor
1802-
<span class="hljs-keyword">with</span> ThreadPoolExecutor(max_workers=<span class="hljs-keyword">None</span>) <span class="hljs-keyword">as</span> executor:
1802+
<span class="hljs-keyword">with</span> ThreadPoolExecutor(max_workers=<span class="hljs-keyword">None</span>) <span class="hljs-keyword">as</span> executor: <span class="hljs-comment"># None == `n_cores * 5`.</span>
18031803
&lt;iter&gt; = executor.map(<span class="hljs-keyword">lambda</span> x: x + <span class="hljs-number">1</span>, range(<span class="hljs-number">3</span>)) <span class="hljs-comment"># (1, 2, 3)</span>
18041804
&lt;iter&gt; = executor.map(<span class="hljs-keyword">lambda</span> x, y: x + y, <span class="hljs-string">'abc'</span>, <span class="hljs-string">'123'</span>) <span class="hljs-comment"># ('a1', 'b2', 'c3')</span>
18051805
&lt;Future&gt; = executor.submit(&lt;function&gt; [, &lt;arg_1&gt;, ...])
18061806
</code></pre></div>
18071807

1808-
<pre><code class="python language-python hljs">&lt;bool&gt; = &lt;Future&gt;.done() <span class="hljs-comment"># Checks if thread has finished executing.</span>
1808+
<div><h4 id="future">Future</h4><pre><code class="python language-python hljs">&lt;bool&gt; = &lt;Future&gt;.done() <span class="hljs-comment"># Checks if thread has finished executing.</span>
18091809
&lt;obj&gt; = &lt;Future&gt;.result() <span class="hljs-comment"># Waits for thread to finish and returns result.</span>
1810-
</code></pre>
1810+
</code></pre></div>
1811+
18111812
<div><h3 id="queue">Queue</h3><p><strong>A thread-safe FIFO queue. For LIFO queue use LifoQueue.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> queue <span class="hljs-keyword">import</span> Queue
18121813
&lt;Queue&gt; = Queue(maxsize=<span class="hljs-number">0</span>)
18131814
</code></pre></div>

0 commit comments

Comments
 (0)