Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from threading import Thread
- from time import sleep
- from random import randint
- thrd = 1
- def threaded_function():
- global thrd
- print('-> 1 thread is running\r\n')
- thrd = thrd + 1
- sleep(randint(1, 5))
- print('<- 1 thread is stopped\n')
- thrd = thrd - 1
- def threaded_function1():
- global thrd
- print('-> 2 thread is running\r\n')
- thrd = thrd + 1
- sleep(randint(1, 5))
- print('<- 2 thread is stopped\n')
- thrd = thrd - 1
- def threaded_function2():
- global thrd
- print('-> 3 thread is running\r\n')
- thrd = thrd + 1
- sleep(randint(1, 5))
- print('<- 3 thread is stopped\n')
- thrd = thrd - 1
- def threaded_function3():
- global thrd
- print('-> 4 thread is running\r\n')
- thrd = thrd + 1
- sleep(randint(1, 5))
- print('<- 4 thread is stopped\n')
- thrd = thrd - 1
- def threaded_function4():
- global thrd
- print('-> 5 thread is running\r\n')
- thrd = thrd + 1
- sleep(randint(1, 5))
- print('<- 5 thread is stopped\n')
- thrd = thrd - 1
- def threads_start():
- Thread(target = threaded_function).start()
- Thread(target = threaded_function1).start()
- Thread(target = threaded_function2).start()
- Thread(target = threaded_function3).start()
- Thread(target = threaded_function4).start()
- def main():
- raw_input("Press enter to start")
- threads_start()
- while 1>0:
- if thrd == 1:
- key = raw_input("Press Enter to continue,\r\n press Ctrl + C to close: ")
- threads_start()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement