Created
September 15, 2014 02:00
-
-
Save TheWaWaR/9492d2b8ded50022a9c8 to your computer and use it in GitHub Desktop.
Sample for gevent producer customer.
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
#!/usr/bin/env python | |
#coding: utf-8 | |
from gevent import monkey | |
monkey.patch_all() | |
import gevent | |
from gevent.queue import Queue | |
q = Queue(3) | |
def custom(): | |
while True: | |
print 'Getting......' | |
item = q.get(block=True) | |
print 'Got:', item | |
gevent.sleep(4) | |
def produce(): | |
i = 0 | |
while True: | |
print 'Putting......' | |
i += 1 | |
q.put(i, block=True) | |
print 'Put:', i | |
gevent.sleep(1) | |
customer = gevent.spawn(custom) | |
producer = gevent.spawn(produce) | |
gevent.joinall([ | |
customer, producer | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment