which python library runs a function as thread code example
Example 1: python thread function
x = threading.Thread(target=thread_function, args=(1,), daemon=True)
x.start()
Example 2: how to run same function on multiple threads in pyhton
import multiprocessing
def worker(num):
""" Worker procedure
"""
print('Worker:', str(num))
if __name__ == '__main__':
jobs = []
jobs_num = 5
for i in range(jobs_num):
p1 = multiprocessing.Process(target=worker, args=(i,))
jobs.append(p1)
p2 = multiprocessing.Process(target=worker, args=(i+10,))
jobs.append(p2)
p1.start()
p2.start()