Created
March 4, 2021 20:43
-
-
Save jaymody/b1127e037c309d06b2bb7de69b06d9cd to your computer and use it in GitHub Desktop.
Get and send data asyncio queue.
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 | |
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