how to multi thread python

Solutions on MaxInterview for how to multi thread python by the best coders in the world

showing results for - "how to multi thread python"
Gabriela
25 Nov 2019
1from Threading import Thread
2
3def thread_fn():
4	# do stuff here. 
5    
6num_threads = 10
7for i in range(num_threads):
8	t = Thread(target=thread_fn, args=[]) # args[] contains function arguments
9    t.start()                             # thread is now running!
10    threads.append(t)                     # hold onto it for it later
11
12for t in threads:
13    t.join()                              # waits for each t to finish