Skip to content

Instantly share code, notes, and snippets.

@povilasb
Created June 24, 2016 19:19
Show Gist options
  • Save povilasb/78431d01225d7ec621367a5d082800f6 to your computer and use it in GitHub Desktop.
Save povilasb/78431d01225d7ec621367a5d082800f6 to your computer and use it in GitHub Desktop.
import asyncio
@asyncio.coroutine
def queue_loader(packet_queue):
for i in range(1, 10):
yield from packet_queue.put('item%' % i)
yield from asyncio.sleep(1)
@asyncio.coroutine
def packet_printer(packet_queue):
while True:
print('blocked')
item = yield from packet_queue.get()
print('Works: ', item)
event_loop = asyncio.get_event_loop()
packet_queue = asyncio.Queue()
tasks = [
event_loop.create_task(queue_loader(packet_queue)),
event_loop.create_task(packet_printer(packet_queue)),
]
asyncio.wait(tasks)
event_loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment