Created
April 9, 2014 10:13
-
-
Save anonymous/10250831 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 | |
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() |
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
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