I want to run 2 functions in parallel and use a returned value from one function (which is being stored in a list continuously) to be used in another function.
I have written some functions to achieve the above (taken help from some previous post on this forum).
u=[]
def func_a():
Num1=10000
for i1 in range(callNum1):
ul = <some_function_returns_a_value>
u.append(ul)
def func_b():
Num2=10000
time.sleep(30)
for i2 in range(Num2):
ul1=u.pop(i2)
print ul1
def RunP(*fns):
proc = []
for fn in fns:
p = Process(target=fn)
p.start()
proc.append(p)
for p in proc:
p.join()
I call both the functions like the following
RunP(func_a, func_b)
But when I run this, I get this error :
RunP(func_a, func_b)
Process Process-2:
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/multiprocessing-2.6.2.1-py2.4-linux-i686.egg/multiprocessing/process.py", line 237, in _bootstrap
self.run()
File "/usr/lib/python2.4/site-packages/multiprocessing-2.6.2.1-py2.4-linux-i686.egg/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "test.py", line 419, in func_b
ul1=u.pop(i2)
IndexError: pop from empty list
Please help me achieve the intended task.
Sounds like you want to use a
Queue.Here’s a quick’n’dirty example which is somewhat similar to your code:
When I run this, it prints: