Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.