fork download
  1. import asyncio
  2. import threading
  3.  
  4.  
  5. def ask(q):
  6. async def put_to_q(q, elem):
  7. await q.put(elem)
  8.  
  9. while True:
  10. res = input('Enter data: ')
  11. asyncio.run(put_to_q(q, res))
  12.  
  13.  
  14. async def produce(q):
  15. while True:
  16. elem = await q.get()
  17. print(f'Processing {elem} ...')
  18. await asyncio.sleep(3)
  19. print(f'{elem} done')
  20.  
  21.  
  22. async def main():
  23. queue = asyncio.Queue()
  24. print('Main started')
  25. t = threading.Thread(target=lambda: ask(queue))
  26. t.start()
  27. await produce(queue)
  28.  
  29.  
  30. if __name__ == '__main__':
  31. asyncio.run(main())
Time limit exceeded #stdin #stdout 5s 16572KB
stdin
Standard input is empty
stdout
Main started
Enter data: