Advertisement
robertvari

Simple Event

Feb 2nd, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import time, random, threading
  2.  
  3. download_event = threading.Event()
  4. data_ready_even = threading.Event()
  5.  
  6. def downloader_worker():
  7.     print("downloader_worker started")
  8.  
  9.     time.sleep(random.randint(2,10))
  10.  
  11.     download_event.set()
  12.     print("download ready!")
  13.  
  14. def process_worker():
  15.     download_event.wait()
  16.  
  17.     print("process_download started")
  18.  
  19.     time.sleep(random.randint(2, 10))
  20.  
  21.     print("process_download ready!")
  22.  
  23. downloader_thread = threading.Thread(target=downloader_worker)
  24. process_worker_thread = threading.Thread(target=process_worker)
  25.  
  26. downloader_thread.start()
  27. process_worker_thread.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement