Skip to content

Commit 9bf0fbb

Browse files
committed
Merge remote-tracking branch 'origin/subprocessexample'
Conflicts: tutorial.md
2 parents 58120ab + aa7f770 commit 9bf0fbb

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

tutorial.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -973,21 +973,31 @@ As of gevent 1.0, ``gevent.subprocess`` -- a patched version of Python's
973973
subprocesses.
974974

975975
<pre>
976-
<code class="python">import gevent
976+
<code class="python">
977+
import gevent
977978
from gevent.subprocess import Popen, PIPE
978979

979-
# Uses a green pipe which is cooperative
980-
sub = Popen(['uname'], stdout=PIPE)
981-
read_output = gevent.spawn(sub.stdout.read)
982-
983-
output = read_output.join()
984-
print(output.value)
985-
</code>
980+
def cron():
981+
while True:
982+
print "cron"
983+
gevent.sleep(0.2)
984+
985+
g = gevent.spawn(cron)
986+
sub = Popen(['sleep 1; uname'], stdout=PIPE, shell=True)
987+
out, err = sub.communicate()
988+
g.kill()
989+
print out.rstrip()
986990
</pre>
987991

988992
<pre>
989-
<code class="python">Linux
990-
</code>
993+
<code class="python">
994+
cron
995+
cron
996+
cron
997+
cron
998+
cron
999+
Linux
1000+
<code>
9911001
</pre>
9921002

9931003
Many people also want to use ``gevent`` and ``multiprocessing`` together. One of

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