Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 180b1d5

Browse files
committed
Threading
1 parent d318f2b commit 180b1d5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,8 +2118,8 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
21182118

21192119
#### Or:
21202120
```python
2121-
with <lock>: # Enters the block by calling acquire(),
2122-
... # and exits it with release(), even on error.
2121+
with <lock>: # Enters the block by calling acquire() and
2122+
... # exits it with release(), even on error.
21232123
```
21242124

21252125
### Semaphore, Event, Barrier
@@ -2141,8 +2141,8 @@ with <lock>: # Enters the block by calling acq
21412141
### Thread Pool Executor
21422142
```python
21432143
<Exec> = ThreadPoolExecutor(max_workers=None) # Or: `with ThreadPoolExecutor() as <name>: …`
2144-
<iter> = <Exec>.map(<func>, <args_1>, ...) # A multithreaded non-lazy map(). Keeps order.
2145-
<Futr> = <Exec>.submit(<func>, <arg_1>, ...) # Starts a thread and returns its Future object.
2144+
<iter> = <Exec>.map(<func>, <args_1>, ...) # Multithreaded and non-lazy map(). Keeps order.
2145+
<Futr> = <Exec>.submit(<func>, <arg_1>, ...) # Creates a thread and returns its Future object.
21462146
<Exec>.shutdown(wait=True) # Blocks until all threads finish executing.
21472147
```
21482148

@@ -2153,7 +2153,7 @@ with <lock>: # Enters the block by calling acq
21532153
<iter> = as_completed(<coll_of_Futures>) # Each Future is yielded as it completes.
21542154
```
21552155
* **Map() and as_completed() also accept 'timeout' argument that causes TimeoutError if result isn't available in 'timeout' seconds after next() is called.**
2156-
* **Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. It's exception() method returns exception or None.**
2156+
* **Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. Its exception() method returns exception or None.**
21572157
* **An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. Arguments and results must be [pickable](#pickle).**
21582158

21592159

index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<body>
5656
<header>
57-
<aside>June 1, 2023</aside>
57+
<aside>June 4, 2023</aside>
5858
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
5959
</header>
6060

@@ -1752,8 +1752,8 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
17521752
&lt;lock&gt;.release() <span class="hljs-comment"># Makes the lock available again.</span>
17531753
</code></pre></div>
17541754

1755-
<div><h4 id="or-1">Or:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">with</span> &lt;lock&gt;: <span class="hljs-comment"># Enters the block by calling acquire(),</span>
1756-
... <span class="hljs-comment"># and exits it with release(), even on error.</span>
1755+
<div><h4 id="or-1">Or:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">with</span> &lt;lock&gt;: <span class="hljs-comment"># Enters the block by calling acquire() and</span>
1756+
... <span class="hljs-comment"># exits it with release(), even on error.</span>
17571757
</code></pre></div>
17581758

17591759
<div><h3 id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><code class="python language-python hljs">&lt;Semaphore&gt; = Semaphore(value=<span class="hljs-number">1</span>) <span class="hljs-comment"># Lock that can be acquired by 'value' threads.</span>
@@ -1769,8 +1769,8 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
17691769
</code></pre></div>
17701770

17711771
<div><h3 id="threadpoolexecutor">Thread Pool Executor</h3><pre><code class="python language-python hljs">&lt;Exec&gt; = ThreadPoolExecutor(max_workers=<span class="hljs-keyword">None</span>) <span class="hljs-comment"># Or: `with ThreadPoolExecutor() as &lt;name&gt;: …`</span>
1772-
&lt;iter&gt; = &lt;Exec&gt;.map(&lt;func&gt;, &lt;args_1&gt;, ...) <span class="hljs-comment"># A multithreaded non-lazy map(). Keeps order.</span>
1773-
&lt;Futr&gt; = &lt;Exec&gt;.submit(&lt;func&gt;, &lt;arg_1&gt;, ...) <span class="hljs-comment"># Starts a thread and returns its Future object.</span>
1772+
&lt;iter&gt; = &lt;Exec&gt;.map(&lt;func&gt;, &lt;args_1&gt;, ...) <span class="hljs-comment"># Multithreaded and non-lazy map(). Keeps order.</span>
1773+
&lt;Futr&gt; = &lt;Exec&gt;.submit(&lt;func&gt;, &lt;arg_1&gt;, ...) <span class="hljs-comment"># Creates a thread and returns its Future object.</span>
17741774
&lt;Exec&gt;.shutdown(wait=<span class="hljs-keyword">True</span>) <span class="hljs-comment"># Blocks until all threads finish executing.</span>
17751775
</code></pre></div>
17761776

@@ -1781,7 +1781,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
17811781
</code></pre>
17821782
<ul>
17831783
<li><strong>Map() and as_completed() also accept 'timeout' argument that causes TimeoutError if result isn't available in 'timeout' seconds after next() is called.</strong></li>
1784-
<li><strong>Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. It's exception() method returns exception or None.</strong></li>
1784+
<li><strong>Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. Its exception() method returns exception or None.</strong></li>
17851785
<li><strong>An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. Arguments and results must be <a href="#pickle">pickable</a>.</strong></li>
17861786
</ul>
17871787
<div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> operator <span class="hljs-keyword">as</span> op
@@ -2934,7 +2934,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29342934

29352935

29362936
<footer>
2937-
<aside>June 1, 2023</aside>
2937+
<aside>June 4, 2023</aside>
29382938
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29392939
</footer>
29402940

0 commit comments

Comments
 (0)