Created
June 24, 2016 19:19
-
-
Save povilasb/78431d01225d7ec621367a5d082800f6 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 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