Skip to content

Commit efde95e

Browse files
committed
Introspection, Threading, Coroutines
1 parent ce55a2b commit efde95e

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ Introspection
22182218
-------------
22192219
```python
22202220
<list> = dir() # Local names of variables, functions, classes and modules.
2221-
<dict> = vars() # Dict of local names and their objects. Also locals().
2221+
<dict> = vars() # Dict of local names and their objects. Same as locals().
22222222
<dict> = globals() # Dict of global names and their objects, e.g. __builtin__.
22232223
```
22242224

@@ -2260,20 +2260,20 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
22602260
```python
22612261
<lock> = Lock/RLock() # RLock can only be released by acquirer thread.
22622262
<lock>.acquire() # Blocks (waits) until lock becomes available.
2263-
<lock>.release() # It makes the acquired lock available again.
2263+
<lock>.release() # Releases the lock so it can be acquired again.
22642264
```
22652265

22662266
#### Or:
22672267
```python
22682268
with <lock>: # Enters the block by calling method acquire().
2269-
... # Exits by calling release(), even on error.
2269+
... # Exits it by calling release(), even on error.
22702270
```
22712271

22722272
### Semaphore, Event, Barrier
22732273
```python
22742274
<Semaphore> = Semaphore(value=1) # Lock that can be acquired by 'value' threads.
22752275
<Event> = Event() # Method wait() blocks until set() is called.
2276-
<Barrier> = Barrier(n_times) # Wait() blocks until it's called n times.
2276+
<Barrier> = Barrier(<int>) # Wait() blocks until it's called int times.
22772277
```
22782278

22792279
### Queue
@@ -2307,7 +2307,7 @@ with <lock>: # Enters the block by calling met
23072307
Coroutines
23082308
----------
23092309
* **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.**
2310-
* **Coroutine definition starts with `'async'` and its call with `'await'` keyword.**
2310+
* **Coroutine definition starts with `'async'` keyword and its call with `'await'`.**
23112311
* **Use `'asyncio.run(<coroutine>)'` to start the first/main coroutine.**
23122312

23132313
```python
@@ -2333,7 +2333,7 @@ import asyncio, collections, curses, curses.textpad, enum, random
23332333

23342334
P = collections.namedtuple('P', 'x y') # Position (x and y coordinates).
23352335
D = enum.Enum('D', 'n e s w') # Direction (north, east, etc.).
2336-
W, H = 15, 7 # Width and height constants.
2336+
W, H = 15, 7 # Width and height of the field.
23372337

23382338
def main(screen):
23392339
curses.curs_set(0) # Makes the cursor invisible.

index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<body>
5858
<header>
59-
<aside>September 4, 2025</aside>
59+
<aside>September 5, 2025</aside>
6060
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
6161
</header>
6262

@@ -1833,7 +1833,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
18331833
</code></pre></div>
18341834

18351835
<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><pre><code class="python language-python hljs">&lt;list&gt; = dir() <span class="hljs-comment"># Local names of variables, functions, classes and modules.</span>
1836-
&lt;dict&gt; = vars() <span class="hljs-comment"># Dict of local names and their objects. Also locals().</span>
1836+
&lt;dict&gt; = vars() <span class="hljs-comment"># Dict of local names and their objects. Same as locals().</span>
18371837
&lt;dict&gt; = globals() <span class="hljs-comment"># Dict of global names and their objects, e.g. __builtin__.</span>
18381838
</code></pre></div>
18391839

@@ -1865,16 +1865,16 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
18651865
</ul>
18661866
<div><h3 id="lock">Lock</h3><pre><code class="python language-python hljs">&lt;lock&gt; = Lock/RLock() <span class="hljs-comment"># RLock can only be released by acquirer thread.</span>
18671867
&lt;lock&gt;.acquire() <span class="hljs-comment"># Blocks (waits) until lock becomes available.</span>
1868-
&lt;lock&gt;.release() <span class="hljs-comment"># It makes the acquired lock available again.</span>
1868+
&lt;lock&gt;.release() <span class="hljs-comment"># Releases the lock so it can be acquired again.</span>
18691869
</code></pre></div>
18701870

18711871
<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 method acquire().</span>
1872-
... <span class="hljs-comment"># Exits by calling release(), even on error.</span>
1872+
... <span class="hljs-comment"># Exits it by calling release(), even on error.</span>
18731873
</code></pre></div>
18741874

18751875
<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>
18761876
&lt;Event&gt; = Event() <span class="hljs-comment"># Method wait() blocks until set() is called.</span>
1877-
&lt;Barrier&gt; = Barrier(n_times) <span class="hljs-comment"># Wait() blocks until it's called n times.</span>
1877+
&lt;Barrier&gt; = Barrier(&lt;int&gt;) <span class="hljs-comment"># Wait() blocks until it's called int times.</span>
18781878
</code></pre></div>
18791879

18801880
<div><h3 id="queue">Queue</h3><pre><code class="python language-python hljs">&lt;Queue&gt; = queue.Queue(maxsize=<span class="hljs-number">0</span>) <span class="hljs-comment"># A first-in-first-out queue. It's thread safe.</span>
@@ -1902,7 +1902,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
19021902
</ul>
19031903
<div><h2 id="coroutines"><a href="#coroutines" name="coroutines">#</a>Coroutines</h2><ul>
19041904
<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>
1905-
<li><strong>Coroutine definition starts with <code class="python hljs"><span class="hljs-string">'async'</span></code> and its call with <code class="python hljs"><span class="hljs-string">'await'</span></code> keyword.</strong></li>
1905+
<li><strong>Coroutine definition starts with <code class="python hljs"><span class="hljs-string">'async'</span></code> keyword and its call with <code class="python hljs"><span class="hljs-string">'await'</span></code>.</strong></li>
19061906
<li><strong>Use <code class="python hljs"><span class="hljs-string">'asyncio.run(&lt;coroutine&gt;)'</span></code> to start the first/main coroutine.</strong></li>
19071907
</ul><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> asyncio <span class="hljs-keyword">as</span> aio
19081908
</code></pre></div>
@@ -1921,7 +1921,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
19211921

19221922
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>
19231923
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>
1924-
W, H = <span class="hljs-number">15</span>, <span class="hljs-number">7</span> <span class="hljs-comment"># Width and height constants.</span>
1924+
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>
19251925

19261926
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">(screen)</span>:</span>
19271927
curses.curs_set(<span class="hljs-number">0</span>) <span class="hljs-comment"># Makes the cursor invisible.</span>
@@ -2934,7 +2934,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29342934

29352935

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

parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const COROUTINES =
122122
'\n' +
123123
'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' +
124124
'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' +
125-
'W, H = <span class="hljs-number">15</span>, <span class="hljs-number">7</span> <span class="hljs-comment"># Width and height constants.</span>\n' +
125+
'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' +
126126
'\n' +
127127
'<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">(screen)</span>:</span>\n' +
128128
' curses.curs_set(<span class="hljs-number">0</span>) <span class="hljs-comment"># Makes the cursor invisible.</span>\n' +

0 commit comments

Comments
 (0)