Skip to content

Instantly share code, notes, and snippets.

Created April 9, 2014 10:13
Show Gist options
  • Save anonymous/10250831 to your computer and use it in GitHub Desktop.
Save anonymous/10250831 to your computer and use it in GitHub Desktop.
import asyncio
queue = asyncio.Queue()
@asyncio.coroutine
def sender():
print('sender started')
try:
yield from asyncio.sleep(3)
while True:
data = yield from queue.get()
print('get', data)
except Exception as e:
print(e)
@asyncio.coroutine
def process():
print('process started')
while True:
yield from asyncio.sleep(1)
print('put, count', queue.qsize())
queue.put_nowait('hello')
def main():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.async(process())
asyncio.async(sender())
loop.run_forever()
main()
process started
sender started
put, count 0
put, count 1
get hello
get hello
put, count 0
put, count 0
put, count 1
put, count 2
put, count 3
put, count 4
put, count 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment