Advertisement
Guest User

Untitled

a guest
May 2nd, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import threading
  2. import time
  3.  
  4. start = time.perf_counter()
  5.  
  6. def do_something(seconds):
  7. print(f'Sleeping {seconds} second(s)...')
  8. time.sleep(seconds)
  9.  
  10. threads = []
  11. if __name__ == '__main__':
  12. for _ in range(10):
  13. t = threading.Thread(target=do_something,args=[1.5])
  14. t.start()
  15. threads.append(t)
  16.  
  17. for thread in threads:
  18. thread.join()
  19.  
  20. finish = time.perf_counter()
  21. print(f'Took {round(finish-start,2)} seconds.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement