code_junkie

time.sleep — sleeps thread or process?

Nov 10th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. import time
  2. from threading import Thread
  3.  
  4. class worker(Thread):
  5. def run(self):
  6. for x in xrange(0,11):
  7. print x
  8. time.sleep(1)
  9.  
  10. class waiter(Thread):
  11. def run(self):
  12. for x in xrange(100,103):
  13. print x
  14. time.sleep(5)
  15.  
  16. def run():
  17. worker().start()
  18. waiter().start()
  19.  
  20. >>> thread_test.run()
  21. 0
  22. 100
  23. >>> 1
  24. 2
  25. 3
  26. 4
  27. 5
  28. 101
  29. 6
  30. 7
  31. 8
  32. 9
  33. 10
  34. 102
Add Comment
Please, Sign In to add comment