Advertisement
wagner-cipriano

Working with Threads

Oct 15th, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. #Working with Threads
  2. from __future__ import print_function      #Compatibilidade func print python 2/3
  3. from threading import Thread
  4. from time import sleep
  5. import random
  6.  
  7. #Target function
  8. def worker(tsleep):
  9.     print ('worker ini', tsleep)
  10.     sleep(tsleep)
  11.     print ('worker fim', tsleep)
  12.  
  13. t = Thread(target=worker, args=(random.randrange(10, 20),))
  14. t.start()
  15.  
  16. while t.isAlive():
  17.     sleep(1)
  18.     print('waiting')
  19.  
  20. print('end')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement