Skip to content

Instantly share code, notes, and snippets.

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:
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)
result = loop.run_until_complete(sum_queue_vals(data_q))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment