Browse Source

Threading

pull/46/head
Jure Šorn 5 years ago
parent
commit
ec487e3829
2 changed files with 18 additions and 18 deletions
  1. 18
      README.md
  2. 18
      index.html

18
README.md

@ -2011,14 +2011,14 @@ from threading import Thread, RLock
thread = Thread(target=<function>, args=(<first_arg>, ))
thread.start()
...
<bool> = thread.is_alive() # Checks if thread has finished executing.
thread.join() # Waits for thread to finish.
<bool> = thread.is_alive() # Checks if thread has finished executing.
thread.join() # Waits for thread to finish.
```
### Lock
```python
lock = RLock()
lock.acquire() # Waits for lock to be available.
lock.acquire() # Waits for lock to be available.
...
lock.release()
```
@ -2040,8 +2040,8 @@ with ThreadPoolExecutor(max_workers=None) as executor:
```
```python
<bool> = <Future>.done() # Checks if thread has finished executing.
<obj> = <Future>.result() # Waits for thread to finish and returns result.
<bool> = <Future>.done() # Checks if thread has finished executing.
<obj> = <Future>.result() # Waits for thread to finish and returns result.
```
### Queue
@ -2052,10 +2052,10 @@ from queue import Queue
```
```python
<Queue>.put(<el>) # Blocks until queue stops being full.
<Queue>.put_nowait(<el>) # Raises queue.Full exception if full.
<el> = <Queue>.get() # Blocks until queue stops being empty.
<el> = <Queue>.get_nowait() # Raises _queue.Empty exception if empty.
<Queue>.put(<el>) # Blocks until queue stops being full.
<Queue>.put_nowait(<el>) # Raises queue.Full exception if full.
<el> = <Queue>.get() # Blocks until queue stops being empty.
<el> = <Queue>.get_nowait() # Raises _queue.Empty exception if empty.
```

18
index.html

@ -1771,12 +1771,12 @@ db = connector.connect(host=&lt;str&gt;, user=&lt;str&gt;, password=&lt;str&gt;,
<div><h3 id="thread">Thread</h3><pre><code class="python language-python hljs">thread = Thread(target=&lt;function&gt;, args=(&lt;first_arg&gt;, ))
thread.start()
...
&lt;bool&gt; = thread.is_alive() <span class="hljs-comment"># Checks if thread has finished executing.</span>
thread.join() <span class="hljs-comment"># Waits for thread to finish.</span>
&lt;bool&gt; = thread.is_alive() <span class="hljs-comment"># Checks if thread has finished executing.</span>
thread.join() <span class="hljs-comment"># Waits for thread to finish.</span>
</code></pre></div>
<div><h3 id="lock">Lock</h3><pre><code class="python language-python hljs">lock = RLock()
lock.acquire() <span class="hljs-comment"># Waits for lock to be available.</span>
lock.acquire() <span class="hljs-comment"># Waits for lock to be available.</span>
...
lock.release()
</code></pre></div>
@ -1793,18 +1793,18 @@ lock.release()
&lt;Future&gt; = executor.submit(&lt;function&gt; [, &lt;arg_1&gt;, ...])
</code></pre></div>
<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>
&lt;obj&gt; = &lt;Future&gt;.result() <span class="hljs-comment"># Waits for thread to finish and returns result.</span>
<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>
&lt;obj&gt; = &lt;Future&gt;.result() <span class="hljs-comment"># Waits for thread to finish and returns result.</span>
</code></pre>
<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
&lt;Queue&gt; = Queue(maxsize=<span class="hljs-number">0</span>)
</code></pre></div>
<pre><code class="python language-python hljs">&lt;Queue&gt;.put(&lt;el&gt;) <span class="hljs-comment"># Blocks until queue stops being full.</span>
&lt;Queue&gt;.put_nowait(&lt;el&gt;) <span class="hljs-comment"># Raises queue.Full exception if full.</span>
&lt;el&gt; = &lt;Queue&gt;.get() <span class="hljs-comment"># Blocks until queue stops being empty.</span>
&lt;el&gt; = &lt;Queue&gt;.get_nowait() <span class="hljs-comment"># Raises _queue.Empty exception if empty.</span>
<pre><code class="python language-python hljs">&lt;Queue&gt;.put(&lt;el&gt;) <span class="hljs-comment"># Blocks until queue stops being full.</span>
&lt;Queue&gt;.put_nowait(&lt;el&gt;) <span class="hljs-comment"># Raises queue.Full exception if full.</span>
&lt;el&gt; = &lt;Queue&gt;.get() <span class="hljs-comment"># Blocks until queue stops being empty.</span>
&lt;el&gt; = &lt;Queue&gt;.get_nowait() <span class="hljs-comment"># Raises _queue.Empty exception if empty.</span>
</code></pre>
<div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> operator <span class="hljs-keyword">import</span> add, sub, mul, truediv, floordiv, mod, pow, neg, abs
<span class="hljs-keyword">from</span> operator <span class="hljs-keyword">import</span> eq, ne, lt, le, gt, ge

|||||||
100:0
Loading…
Cancel
Save