Guest User

Untitled

a guest
Nov 9th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import threading
  2. import queue
  3. def printhi():
  4.     print('Printed from child thread:',threading.current_thread().name)
  5.     print('')
  6.     #print('Printed from thread {}'.format(name))
  7. q = queue.Queue()
  8. #print(threading.current_thread())
  9. parent_thread = threading.current_thread()
  10. print('Name is:',parent_thread.name)
  11. #q.put(parent_thread)
  12. count = 0
  13. for i in range(5):
  14.     q.put(threading.Thread(target = printhi,name='Thread {}'.format(count+1)),block=False)
  15.     count += 1
  16. print('About to execute all the child threads:')
  17. while not q.empty():
  18.     (q.get()).start()
  19.    
  20. print('Size of queue now is:',q.qsize())
Add Comment
Please, Sign In to add comment