Created
September 2, 2014 19:51
-
-
Save c0ldlimit/3c71e0d2f7edf907f0fe 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 gevent | |
from gevent.queue import Queue | |
tasks = Queue() | |
def worker(n, work_time): | |
while not tasks.empty(): | |
task = tasks.get() | |
print("Worker %s got tasks %s" % (n, task)) | |
gevent.sleep(work_time) # releases the greenlet to go do something else | |
print("Quitting time %s" % n) | |
def boss(): | |
for i in xrange(1,25): | |
tasks.put_nowait(i) | |
gevent.spawn(boss).join() | |
gevent.joinall([ | |
gevent.spawn(lambda args: worker(*args), ('steve', 0.1)), | |
gevent.spawn(lambda args: worker(*args), ('james', 0.2)), | |
gevent.spawn(lambda args: worker(*args), ('nancy', 0.3)), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment