Skip to content

Commit aa7f770

Browse files
committed
Change cooperative subprocess example.
1 parent dc7ac87 commit aa7f770

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tutorial.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -972,20 +972,30 @@ As of Gevent 1.0, support has been added for cooperative waiting
972972
on subprocess.
973973

974974
<pre>
975-
<code class="python">import gevent
975+
<code class="python">
976+
import gevent
976977
from gevent.subprocess import Popen, PIPE
977978

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

987991
<pre>
988-
<code class="python">Linux
992+
<code class="python">
993+
cron
994+
cron
995+
cron
996+
cron
997+
cron
998+
Linux
989999
<code>
9901000
</pre>
9911001

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