Advertisement
Guest User

Untitled

a guest
May 27th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. from threading import Thread
  2. from time import sleep
  3. from random import randint
  4.  
  5. thrd = 1
  6.  
  7. def threaded_function():
  8.     global thrd
  9.     print('-> 1 thread is running\r\n')
  10.     thrd = thrd + 1
  11.     sleep(randint(1, 5))
  12.     print('<- 1 thread is stopped\n')
  13.     thrd = thrd - 1
  14.        
  15. def threaded_function1():
  16.     global thrd
  17.     print('-> 2 thread is running\r\n')
  18.     thrd = thrd + 1
  19.     sleep(randint(1, 5))
  20.     print('<- 2 thread is stopped\n')
  21.     thrd = thrd - 1
  22.  
  23. def threaded_function2():
  24.     global thrd
  25.     print('-> 3 thread is running\r\n')
  26.     thrd = thrd + 1
  27.     sleep(randint(1, 5))
  28.     print('<- 3 thread is stopped\n')
  29.     thrd = thrd - 1
  30.  
  31.  
  32. def threaded_function3():
  33.     global thrd
  34.     print('-> 4 thread is running\r\n')
  35.     thrd = thrd + 1
  36.     sleep(randint(1, 5))
  37.     print('<- 4 thread is stopped\n')
  38.     thrd = thrd - 1
  39.  
  40. def threaded_function4():
  41.     global thrd
  42.     print('-> 5 thread is running\r\n')
  43.     thrd = thrd + 1
  44.     sleep(randint(1, 5))
  45.     print('<- 5 thread is stopped\n')
  46.     thrd = thrd - 1
  47.  
  48. def threads_start():
  49.     Thread(target = threaded_function).start()
  50.     Thread(target = threaded_function1).start()
  51.     Thread(target = threaded_function2).start()
  52.     Thread(target = threaded_function3).start()
  53.     Thread(target = threaded_function4).start()
  54.  
  55. def main():
  56.     raw_input("Press enter to start")
  57.     threads_start()
  58.     while 1>0:
  59.         if thrd == 1:
  60.             key = raw_input("Press Enter to continue,\r\n press Ctrl + C to close: ")
  61.             threads_start()
  62. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement