<list> = dir() # Local names of variables, functions, classes and modules.
<dict> = vars() # Dict of local names and their objects. Also locals().
<dict> = vars() # Dict of local names and their objects. Same as locals().
<dict> = globals() # Dict of global names and their objects, e.g. __builtin__.
```
@ -2260,20 +2260,20 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
```python
<lock> = Lock/RLock() # RLock can only be released by acquirer thread.
<lock>.acquire() # Blocks (waits) until lock becomes available.
<lock>.release() # It makes the acquired lock available again.
<lock>.release() # Releases the lock so it can be acquired again.
```
#### Or:
```python
with <lock>: # Enters the block by calling method acquire().
... # Exits by calling release(), even on error.
... # Exits it by calling release(), even on error.
```
### Semaphore, Event, Barrier
```python
<Semaphore> = Semaphore(value=1) # Lock that can be acquired by 'value' threads.
<Event> = Event() # Method wait() blocks until set() is called.
<Barrier> = Barrier(n_times) # Wait() blocks until it's called n times.
<Barrier> = Barrier(<int>) # Wait() blocks until it's called int times.
```
### Queue
@ -2307,7 +2307,7 @@ with <lock>: # Enters the block by calling met
Coroutines
----------
* **Coroutines have a lot in common with threads, but unlike threads, they only give up control when they call another coroutine and they don’t consume as much memory.**
* **Coroutine definition starts with `'async'` and its call with `'await'` keyword.**
* **Coroutine definition starts with `'async'`keyword and its call with `'await'`.**
* **Use `'asyncio.run(<coroutine>)'` to start the first/main coroutine.**
@ -1833,7 +1833,7 @@ CRITICAL:my_module:Running out of disk space.
</code></pre></div>
<div><h2id="introspection"><ahref="#introspection"name="introspection">#</a>Introspection</h2><pre><codeclass="python language-python hljs"><list> = dir() <spanclass="hljs-comment"># Local names of variables, functions, classes and modules.</span>
<dict> = vars() <spanclass="hljs-comment"># Dict of local names and their objects. Also locals().</span>
<dict> = vars() <spanclass="hljs-comment"># Dict of local names and their objects. Same as locals().</span>
<dict> = globals() <spanclass="hljs-comment"># Dict of global names and their objects, e.g. __builtin__.</span>
<div><h3id="lock">Lock</h3><pre><codeclass="python language-python hljs"><lock> = Lock/RLock() <spanclass="hljs-comment"># RLock can only be released by acquirer thread.</span>
<lock>.acquire() <spanclass="hljs-comment"># Blocks (waits) until lock becomes available.</span>
<lock>.release() <spanclass="hljs-comment"># It makes the acquired lock available again.</span>
<lock>.release() <spanclass="hljs-comment"># Releases the lock so it can be acquired again.</span>
</code></pre></div>
<div><h4id="or-1">Or:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">with</span><lock>: <spanclass="hljs-comment"># Enters the block by calling method acquire().</span>
... <spanclass="hljs-comment"># Exits by calling release(), even on error.</span>
... <spanclass="hljs-comment"># Exits it by calling release(), even on error.</span>
</code></pre></div>
<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 by 'value' threads.</span>
<Event> = Event() <spanclass="hljs-comment"># Method wait() blocks until set() is called.</span>
<Barrier> = Barrier(n_times)<spanclass="hljs-comment"># Wait() blocks until it's called n times.</span>
<Barrier> = Barrier(<int>) <spanclass="hljs-comment"># Wait() blocks until it's called int times.</span>
<li><strong>Coroutines have a lot in common with threads, but unlike threads, they only give up control when they call another coroutine and they don’t consume as much memory.</strong></li>
<li><strong>Coroutine definition starts with <codeclass="python hljs"><spanclass="hljs-string">'async'</span></code> and its call with <codeclass="python hljs"><spanclass="hljs-string">'await'</span></code> keyword.</strong></li>
<li><strong>Coroutine definition starts with <codeclass="python hljs"><spanclass="hljs-string">'async'</span></code>keyword and its call with <codeclass="python hljs"><spanclass="hljs-string">'await'</span></code>.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'asyncio.run(<coroutine>)'</span></code> to start the first/main coroutine.</strong></li>
P = collections.namedtuple(<spanclass="hljs-string">'P'</span>, <spanclass="hljs-string">'x y'</span>) <spanclass="hljs-comment"># Position (x and y coordinates).</span>
D = enum.Enum(<spanclass="hljs-string">'D'</span>, <spanclass="hljs-string">'n e s w'</span>) <spanclass="hljs-comment"># Direction (north, east, etc.).</span>
W, H = <spanclass="hljs-number">15</span>, <spanclass="hljs-number">7</span><spanclass="hljs-comment"># Width and height constants.</span>
W, H = <spanclass="hljs-number">15</span>, <spanclass="hljs-number">7</span><spanclass="hljs-comment"># Width and height of the field.</span>
'P = collections.namedtuple(<span class="hljs-string">\'P\'</span>, <span class="hljs-string">\'x y\'</span>) <span class="hljs-comment"># Position (x and y coordinates).</span>\n'+
'D = enum.Enum(<span class="hljs-string">\'D\'</span>, <span class="hljs-string">\'n e s w\'</span>) <span class="hljs-comment"># Direction (north, east, etc.).</span>\n'+
'W, H = <span class="hljs-number">15</span>, <span class="hljs-number">7</span> <span class="hljs-comment"># Width and height constants.</span>\n'+
'W, H = <span class="hljs-number">15</span>, <span class="hljs-number">7</span> <span class="hljs-comment"># Width and height of the field.</span>\n'+