Advertisement
Guest User

Untitled

a guest
Aug 26th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. from threading import Thread
  2.  
  3. n = 5
  4.  
  5. def foobar():
  6.     print('foobar')
  7.  
  8. def threads(n):
  9.     for n in range(n):
  10.         yield Thread(target=foobar)
  11.  
  12. thread_list = list()
  13.  
  14. for thread in threads(n):
  15.     thread_list.append(thread)
  16.  
  17. for thread in thread_list:
  18.     thread.start()
  19.  
  20. for thread in thread_list:
  21.     thread.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement