-
-
Save AaronO/6443329 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import gevent | |
def f(x): | |
gevent.sleep(1) | |
def main(): | |
print 'pid =', os.getpid() | |
print 'spawn...' | |
jobs = [] | |
for y in xrange(5): | |
for x in xrange(10**5): | |
jobs.append(gevent.spawn(f, x)) | |
gevent.sleep(2) | |
print 'done spawning' | |
# loop infinitely | |
while True: | |
if jobs is not None and all([job.ready() for job in jobs]): | |
gevent.joinall(jobs) | |
print 'all jobs completed' | |
jobs = None | |
return 'Done' | |
gevent.sleep(2) | |
# Join | |
gevent.joinall([gevent.spawn(main)]) | |
while True: | |
time.sleep(1) | |
print('Finished') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import gevent | |
def f(x): | |
gevent.sleep(1) | |
def main(): | |
print 'pid =', os.getpid() | |
print 'spawn...' | |
jobs = [] | |
for y in xrange(5): | |
for x in xrange(10**5): | |
jobs.append(gevent.spawn(f, x)) | |
gevent.sleep(2) | |
print 'done spawning' | |
# loop infinitely | |
while True: | |
if jobs is not None and all([job.ready() for job in jobs]): | |
#gevent.joinall(jobs) | |
print 'all jobs completed' | |
jobs = None | |
#return 'Done' | |
gevent.sleep(2) | |
# Join | |
gevent.joinall([gevent.spawn(main)]) | |
while True: | |
time.sleep(1) | |
print('Finished') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment