Skip to content

Instantly share code, notes, and snippets.

@tomchristie
Created June 9, 2017 09:50
Show Gist options
  • Save tomchristie/528711c4e6b6d14f4e8b34ecbd7c851e to your computer and use it in GitHub Desktop.
Save tomchristie/528711c4e6b6d14f4e8b34ecbd7c851e to your computer and use it in GitHub Desktop.
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