n0va_sa

Python_thread_program_1

Sep 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # it's a python2 program #
  2.  
  3. import threading
  4. import time
  5. def printHello():
  6.     print ":::Hello USER:::"
  7.     print "GOING TO SLEEP .."
  8.     time.sleep(2)
  9.     print "SLEPT ..."
  10.     return 0
  11.  
  12.  
  13. def main():
  14.     thread_list = []
  15.     for i in range(5):
  16.         t = threading.Thread(target=printHello)
  17.         thread_list.append(t)
  18.         if i is 4:
  19.             print str(thread_list) + " when i is 4"
  20.         t.start()
  21.  
  22.     print str(thread_list) + " At <-- last"
  23.  
  24. def normalMain():
  25.     for i in range(5):
  26.         printHello()
  27.  
  28. main()
Add Comment
Please, Sign In to add comment