fork download
  1. import time
  2. import threading
  3. import queue as Queue
  4.  
  5.  
  6. def f(q):
  7. i = 0
  8. while True:
  9. q.put(i)
  10. print('put', i)
  11. time.sleep(0.5)
  12. i += 1
  13.  
  14. def g(l, q):
  15. while True:
  16. time.sleep(5)
  17. l.acquire()
  18. while not q.empty():
  19. print(q.get())
  20. time.sleep(1)
  21. time.sleep(5)
  22. l.release()
  23.  
  24. Q = Queue.Queue()
  25. l = threading.Lock()
  26. t0 = threading.Thread(target=f, args=[Q])
  27. t0.start()
  28. t1 = threading.Thread(target=g, args=[l, Q])
  29. t1.start()
Time limit exceeded #stdin #stdout 5s 29048KB
stdin
Standard input is empty
stdout
put 0