Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import asyncio
async def sum_queue_vals(q):
result = 0
while True:
val = await q.get()
if val is None:
break
result += val
return result
async def populate_queue(q):
for i in range(1000000):
if not i % 100000:
print(f"put {i} vals in queue so far")
await q.put(i)
# Send "done" sentinal
await q.put(None)
loop = asyncio.get_event_loop()
data_queue_size = 100
data_q = asyncio.Queue(data_queue_size)
loop.create_task(populate_queue(data_q))
result = loop.run_until_complete(sum_queue_vals(data_q))
print(result)
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.