Created
April 13, 2012 12:42
-
-
Save ashpool/2376659 to your computer and use it in GitHub Desktop.
Gevent Queue example
This file contains hidden or 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
from gevent.queue import Queue | |
message_queue = Queue() | |
def receiver(n): | |
while not message_queue.empty(): | |
message = message_queue.get() | |
print('Received %s message %s' % (n, message)) | |
gevent.sleep(0) | |
print('Quitting time!') | |
def sender(): | |
for i in xrange(1,25): | |
message_queue.put_nowait(i) | |
gevent.spawn(sender).join() | |
gevent.joinall([ | |
gevent.spawn(receiver, 'steve'), | |
gevent.spawn(receiver, 'john'), | |
gevent.spawn(receiver, 'nancy'), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment