Created
June 9, 2017 09:50
-
-
Save tomchristie/528711c4e6b6d14f4e8b34ecbd7c851e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import time | |
import threading | |
import queue | |
async def foo(q): | |
i = 0 | |
while True: | |
q.put(i) | |
i += 1 | |
await asyncio.sleep(1) | |
async def bar(q): | |
threading.Thread(target=worker, args=(q,)).start() | |
def worker(q): | |
while True: | |
i = q.get(block=True) | |
print(i) | |
loop = asyncio.get_event_loop() | |
q = queue.Queue() | |
loop.create_task(foo(q)) | |
loop.create_task(bar(q)) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment