import asyncio async def main(): # Make a queue of unbounded length. q = asyncio.Queue() # Publish into it. async def publish(): i = 0 while True: # This will _never_ block, because the queue has no maximum. As a # result, this loop will never yield control to the scheduler to let # any other async code run. await q.put(i) i += 1 async def subscribe(): while True: val = await q.get() print(val) t1 = asyncio.create_task(publish()) t2 = asyncio.create_task(subscribe()) await asyncio.gather(t1, t2) if __name__ == "__main__": asyncio.run(main(), debug=True)