I do have a small python script that aims to run 2 to 3 function in parallel. The scripts seems to work because, I do have the answer, however, it ends with an exception:
import threading
Variable2="V2"
Variable1="V1"
Variable12="V1"
Variable22="V2"
Variable23="V3"
def func1(Variable1,Variable2):
print ("This is my fisrt fucntion ")
print ("My first variable is : %s ") % (Variable1)
print ("My second variable is : %s ") % (Variable2)
def func2(Variable12,Variable22,Variable23):
print ("This is my fisrt fucntion ")
print ("My first variable is : %s ") % (Variable12)
print ("My second variable is : %s ") % (Variable22)
print ("My third variable is : %s ") % (Variable23)
def runInParallel(*fns):
proc = []
for fn, arg in fns:
p = threading.Thread(target=fn, args=(arg,))
p.start()
proc.append(p)
for p in proc:
p.join()
runInParallel( ( func1(Variable1,Variable2,) ), (func2(Variable12,Variable22,Variable23,) ) )
It gives me the following :
This is my fisrt fucntion
My first variable is : V1
My second variable is : V2
This is my fisrt fucntion
My first variable is : V1
My second variable is : V2
My third variable is : V3
Traceback (most recent call last):
File "testpara.py", line 69, in <module>
runInParallel( ( func1(Variable1,Variable2,) ) , (func2(Variable12,Variable22,Variable23,) ) )
File "testpara.py", line 61, in runInParallel
for fn, arg in fns:
TypeError: 'NoneType' object is not iterable
I checked here And it seems one of the parameters of the threading is note passing ( group=None, target=None, name=None, args=(), kwargs={} ).
Any clue?
edit : This seems to be different from here Because variables in that answer is the same one with an updated value.
runInParallel: you're actually evaluating those functions (both in the main thread, so there's no concurrency here) and passing the results of the two functions torunInParallel. Since both functions returnNone, you get the error message you're seeing.runInParallel( ( func1, (Variable1,Variable2,) ), (func2, (Variable12,Variable22,Variable23,) ) )