Skip to content

Instantly share code, notes, and snippets.

@jaymody
Created March 4, 2021 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymody/b1127e037c309d06b2bb7de69b06d9cd to your computer and use it in GitHub Desktop.
Save jaymody/b1127e037c309d06b2bb7de69b06d9cd to your computer and use it in GitHub Desktop.
Get and send data asyncio queue.
import asyncio
from queue import Queue
q = asyncio.Queue()
async def get_data():
while True:
await asyncio.sleep(0.5) # simulate work
print("receiving:", await q.get())
async def send_data():
for i in range(10):
await asyncio.sleep(0.3) # simulate work
print("sending:", i)
await q.put(i)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.create_task(get_data())
loop.run_until_complete(send_data())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment