Skip to content

Commit 23867ed

Browse files
committed
Threading
1 parent 5e31c2a commit 23867ed

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,13 +1981,14 @@ from threading import Thread, RLock
19811981
thread = Thread(target=<function>, args=(<first_arg>, ))
19821982
thread.start()
19831983
...
1984-
thread.join()
1984+
<bool> = thread.is_alive() # Checks if thread has finished executing.
1985+
thread.join() # Waits for thread to finish.
19851986
```
19861987

19871988
### Lock
19881989
```python
19891990
lock = RLock()
1990-
lock.acquire()
1991+
lock.acquire() # Waits for lock to be available.
19911992
...
19921993
lock.release()
19931994
```
@@ -2005,7 +2006,7 @@ from concurrent.futures import ThreadPoolExecutor
20052006
with ThreadPoolExecutor(max_workers=None) as executor:
20062007
<iter> = executor.map(lambda x: x + 1, range(3)) # (1, 2, 3)
20072008
<iter> = executor.map(lambda x, y: x + y, 'abc', '123') # ('a1', 'b2', 'c3')
2008-
<Future> = executor.submit(<function>, <arg_1>, ...)
2009+
<Future> = executor.submit(<function> [, <arg_1>, ...])
20092010
```
20102011

20112012
```python

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,11 +1749,12 @@
17491749
<div><h3 id="thread">Thread</h3><pre><code class="python language-python hljs">thread = Thread(target=&lt;function&gt;, args=(&lt;first_arg&gt;, ))
17501750
thread.start()
17511751
...
1752-
thread.join()
1752+
&lt;bool&gt; = thread.is_alive() <span class="hljs-comment"># Checks if thread has finished executing.</span>
1753+
thread.join() <span class="hljs-comment"># Waits for thread to finish.</span>
17531754
</code></pre></div>
17541755

17551756
<div><h3 id="lock">Lock</h3><pre><code class="python language-python hljs">lock = RLock()
1756-
lock.acquire()
1757+
lock.acquire() <span class="hljs-comment"># Waits for lock to be available.</span>
17571758
...
17581759
lock.release()
17591760
</code></pre></div>
@@ -1767,7 +1768,7 @@
17671768
<span class="hljs-keyword">with</span> ThreadPoolExecutor(max_workers=<span class="hljs-keyword">None</span>) <span class="hljs-keyword">as</span> executor:
17681769
&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>
17691770
&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>
1770-
&lt;Future&gt; = executor.submit(&lt;function&gt;, &lt;arg_1&gt;, ...)
1771+
&lt;Future&gt; = executor.submit(&lt;function&gt; [, &lt;arg_1&gt;, ...])
17711772
</code></pre></div>
17721773

17731774
<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>

0 commit comments

Comments
 (0)