I am new to threading concept in python. Find the below script
def func1(con_no, con_name, *argv):
"This functions takes around 3-4 min to completes"
def func2(con_no, con_name, *argv):
"This functions takes around 5 min to completes"
def runthread(*fns):
proc = []
for fn in fns:
p = Process(target=fn)
p.start()
proc.append(p)
for p in proc:
p.join()
if __name__ == '__main__':
runthread(func1(con_no, con_name), func2(con_no, con_name))
The above code waits for func1() to completes its operation and goes to func2().How to start both the functions parallely, so that func2() do not wait for func1() to complete its operation. Please note I am using python 2.7 version.
Updated the question
You started func1 before runthread is called:
You should write:
runthread(func1, func2)
To pass parameters, read these examples: https://pymotw.com/2/multiprocessing/basics.html
Considering you have con_no
and con_name
initialised with some values, you can use partial
:
from functools import partial
...
runthread(partial(func1, con_no, con_name), partial(func2, con_no, con_name))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.