import asyncio import logging async def producer(queue): i = 0 while True: await asyncio.sleep(60) await queue.put(i) i += 1 async def consumer(queue): while True: try: item = await asyncio.wait_for(queue.get(), 1) except asyncio.TimeoutError: logging.info(f"Queue {queue} is idle") continue logging.info(f"Received {item} from {queue}") queue.task_done() def main(): logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s") queue = asyncio.Queue(maxsize=100) loop = asyncio.get_event_loop() asyncio.ensure_future(producer(queue)) asyncio.ensure_future(consumer(queue)) loop.run_forever() if __name__ == '__main__': main()