Skip to content

Commit 62dd689

Browse files
committed
Merge PR.
1 parent c74c219 commit 62dd689

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

index.html

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ <h2 id="synchronous-asynchronous-execution">Synchronous &amp; Asynchronous Execu
252252
Task 9 done
253253
Asynchronous:
254254
Task 0 done
255-
Task 9 done
256-
Task 1 done
257-
Task 4 done
258255
Task 6 done
259-
Task 5 done
260-
Task 8 done
261256
Task 3 done
262-
Task 2 done
263257
Task 7 done
258+
Task 2 done
259+
Task 1 done
260+
Task 8 done
261+
Task 5 done
262+
Task 9 done
263+
Task 4 done
264264
</pre></code></p>
265265
<p>In the synchronous case all the tasks are run sequentially,
266266
which results in the main programming <em>blocking</em> (
@@ -281,9 +281,9 @@ <h2 id="synchronous-asynchronous-execution">Synchronous &amp; Asynchronous Execu
281281
whole queue. In the async case the maximum runtime is roughly 2
282282
seconds since none of the tasks block the execution of the
283283
others.</p>
284-
<p>A more common use case, fetching data from a server
285-
asynchronously, the runtime of <code>fetch()</code> will differ between
286-
requests given the load on the remote server.</p>
284+
<p>In a more common use case, asynchronously fetching data from a server,
285+
the runtime of <code>fetch()</code> will differ between
286+
requests, depending on the load on the remote server at the time of the request.</p>
287287
<pre><code class="python">import gevent.monkey
288288
gevent.monkey.patch_socket()
289289

@@ -320,9 +320,9 @@ <h2 id="synchronous-asynchronous-execution">Synchronous &amp; Asynchronous Execu
320320

321321
<h2 id="determinism">Determinism</h2>
322322
<p>As mentioned previously, greenlets are deterministic. Given the same
323-
configuration of greenlets and the same set of inputs and they always
324-
produce the same output. For example lets spread a task across a
325-
multiprocessing pool compared to a gevent pool.</p>
323+
configuration of greenlets and the same set of inputs, they always
324+
produce the same output. For example, let's spread a task across a
325+
multiprocessing pool and compare its results to the one of a gevent pool.</p>
326326
<pre>
327327
<code class="python">
328328
import time
@@ -369,14 +369,13 @@ <h2 id="determinism">Determinism</h2>
369369
concurrency", they still can experience some of the same problems
370370
that POSIX threads and processes experience.</p>
371371
<p>The perennial problem involved with concurrency is known as a
372-
<em>race condition</em>. Simply put is when two concurrent threads
372+
<em>race condition</em>. Simply put, a race condition occurs when two concurrent threads
373373
/ processes depend on some shared resource but also attempt to
374-
modify this value. This results in resources whose values become
374+
modify this value. This results in resources which values become
375375
time-dependent on the execution order. This is a problem, and in
376376
general one should very much try to avoid race conditions since
377-
they result program behavior which is globally
378-
non-deterministic.</p>
379-
<p>The best approach to this is to simply avoid all global state all
377+
they result in a globally non-deterministic program behavior.</p>
378+
<p>The best approach to this is to simply avoid all global state at all
380379
times. Global state and import-time side effects will always come
381380
back to bite you!</p>
382381
<h2 id="spawning-greenlets">Spawning Greenlets</h2>
@@ -445,17 +444,16 @@ <h2 id="spawning-greenlets">Spawning Greenlets</h2>
445444
<h2 id="greenlet-state">Greenlet State</h2>
446445
<p>Like any other segment of code, Greenlets can fail in various
447446
ways. A greenlet may fail to throw an exception, fail to halt or
448-
consume too many system resources.</p></p>
447+
consume too many system resources.</p>
449448
<p>The internal state of a greenlet is generally a time-dependent
450449
parameter. There are a number of flags on greenlets which let
451-
you monitor the state of the thread</p>
452-
450+
you monitor the state of the thread:</p>
453451
<ul>
454-
<li><code>started</code> -- Boolean, indicates whether the Greenlet has been started. </li></li>
455-
<li><code>ready()</code> -- Boolean, indicates whether the Greenlet has halted</li></li>
456-
<li><code>successful()</code> -- Boolean, indicates whether the Greenlet has halted and not thrown an exception</li></li>
457-
<li><code>value</code> -- arbitrary, the value returned by the Greenlet</li></li>
458-
<li><code>exception</code> -- exception, uncaught exception instance thrown inside the greenlet</li></li>
452+
<li><code>started</code> -- Boolean, indicates whether the Greenlet has been started</li>
453+
<li><code>ready()</code> -- Boolean, indicates whether the Greenlet has halted</li>
454+
<li><code>successful()</code> -- Boolean, indicates whether the Greenlet has halted and not thrown an exception</li>
455+
<li><code>value</code> -- arbitrary, the value returned by the Greenlet</li>
456+
<li><code>exception</code> -- exception, uncaught exception instance thrown inside the greenlet</li>
459457
</ul>
460458
<pre><code class="python">
461459
import gevent
@@ -556,7 +554,7 @@ <h2 id="timeouts">Timeouts</h2>
556554
</code>
557555
</pre>
558556

559-
<p>Or with a context manager in a <code>with</code> statement.</p>
557+
<p>They can also be used with a context manager, in a <code>with</code> statement.</p>
560558
<pre>
561559
<code class="python">import gevent
562560
from gevent import Timeout
@@ -642,8 +640,8 @@ <h2 id="monkeypatching">Monkeypatching</h2>
642640
After monkey patch
643641
class 'gevent.socket.socket'
644642

645-
After monkey patch
646643
built-in function select
644+
After monkey patch
647645
function select at 0x1924de8
648646
</code>
649647
</pre>
@@ -664,7 +662,7 @@ <h2 id="monkeypatching">Monkeypatching</h2>
664662
of our gevent stack.</p>
665663
<p>This lets us integrate libraries that would not normally work with
666664
gevent without ever writing a single line of code. While monkey-patching
667-
is still evil, in this case it is a "usefull evil".</p>
665+
is still evil, in this case it is a "useful evil".</p>
668666
<h1 id="data-structures">Data Structures</h1>
669667
<h2 id="events">Events</h2>
670668
<p>Events are a form of asynchronous communication between
@@ -801,7 +799,7 @@ <h2 id="queues">Queues</h2>
801799
either <code>gevent.queue.Empty</code> or
802800
<code>gevent.queue.Full</code> in the operation is not possible.</p>
803801
<p>In this example we have the boss running simultaneously to the
804-
workers and have a restriction on the Queue that it can contain no
802+
workers and have a restriction on the Queue preventing it from containing
805803
more than three elements. This restriction means that the <code>put</code>
806804
operation will block until there is space on the queue.
807805
Conversely the <code>get</code> operation will block if there are
@@ -910,9 +908,8 @@ <h2 id="groups-and-pools">Groups and Pools</h2>
910908
fizz
911909
fizz
912910
</pre></code></p>
913-
<p>This is very usefull for managing groups of asynchronous tasks
914-
that.</p>
915-
<p>As mentioned above Group also provides an API for dispatching
911+
<p>This is very useful for managing groups of asynchronous tasks.</p>
912+
<p>As mentioned above, <code>Group</code> also provides an API for dispatching
916913
jobs to grouped greenlets and collecting their results in various
917914
ways.</p>
918915
<pre><code class="python">
@@ -949,11 +946,11 @@ <h2 id="groups-and-pools">Groups and Pools</h2>
949946
<p></code>
950947
<pre><code class="python">
951948
Size of group 3
952-
Hello from Greenlet 42121488
949+
Hello from Greenlet 20398800
953950
Size of group 3
954-
Hello from Greenlet 42119248
951+
Hello from Greenlet 20399280
955952
Size of group 3
956-
Hello from Greenlet 42120208
953+
Hello from Greenlet 20400240
957954
Ordered
958955
('task', 0)
959956
('task', 1)
@@ -969,7 +966,6 @@ <h2 id="groups-and-pools">Groups and Pools</h2>
969966
tasks in parallel.</p>
970967
<pre><code class="python">
971968
import gevent
972-
from gevent import getcurrent
973969
from gevent.pool import Pool
974970

975971
pool = Pool(2)
@@ -1065,8 +1061,8 @@ <h2 id="locks-and-semaphores">Locks and Semaphores</h2>
10651061
ensure that resources are only in use at one time in the context
10661062
of a program.</p>
10671063
<h2 id="thread-locals">Thread Locals</h2>
1068-
<p>Gevnet also allows you to specify data which is local the
1069-
greenlet context. Internally this is implemented as a global
1064+
<p>Gevent also allows you to specify data which is local to the
1065+
greenlet context. Internally, this is implemented as a global
10701066
lookup which addresses a private namespace keyed by the
10711067
greenlet's <code>getcurrent()</code> value.</p>
10721068
<pre><code class="python">
@@ -1142,8 +1138,8 @@ <h2 id="thread-locals">Thread Locals</h2>
11421138
<code>
11431139
</pre>
11441140

1145-
<p>Flask's system is more a bit sophisticated than this example, but the
1146-
idea of using thread locals as local session storage is nontheless the
1141+
<p>Flask's system is a bit more sophisticated than this example, but the
1142+
idea of using thread locals as local session storage is nonetheless the
11471143
same.</p>
11481144
<h2 id="subprocess">Subprocess</h2>
11491145
<p>As of Gevent 1.0, support has been added for cooperative waiting

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy