run two similar functions simultaneously python

Solutions on MaxInterview for run two similar functions simultaneously python by the best coders in the world

showing results for - "run two similar functions simultaneously python"
Luna
01 Jan 2018
1#use threading instead of multiprocessing
2#by @devDavmen
3## EXAMPLE 101 ##
4import threading
5
6def a():
7    print("Function a is running at time: " + str(int(time.time())) + " seconds.")
8
9    
10def b():
11    print("Function b is running at time: " + str(int(time.time())) + " seconds.")
12
13threading.Thread(target=a).start() 
14## OUTPUT >>>  Function a is running at time: 1585338789 seconds.
15threading.Thread(target=b).start() 
16## OUTPUT >>>  Function b is running at time: 1585338789 seconds.
17
18
19## EXAMPLE 2 ##
20import threading
21
22def f():
23    print "abc"
24
25thread = threading.Thread(target=f)
26thread.start()
27## OUTPUT >> abc