run 2 def python

Solutions on MaxInterview for run 2 def python by the best coders in the world

showing results for - "run 2 def python"
Paolo
14 Nov 2016
1from threading import Thread
2from time import sleep
3# use Thread to run def in background
4# Example:
5def func1():
6    while True:
7        sleep(1)
8        print("Working")
9
10def func2():
11    while True:
12        sleep(2)
13        print("Working2")
14
15if __name__ == '__main__':
16    Thread(target = func1).start()
17    Thread(target = func2).start()