-
-
Save asvetlov/10267944 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 sender(queue): | |
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(queue): | |
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) | |
loop = asyncio.get_event_loop() | |
queue = asyncio.Queue() | |
asyncio.async(process(queue)) | |
asyncio.async(sender(queue)) | |
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 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
get hello | |
put, count 0 | |
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