I want to parallelize some python code with IPython.parallel
and have the problem, that IPython detects closures while executing a parallel function.
My environment get's initialized by:
from IPython.parallel import Client
c = Client()
v = c.direct_view()
qs = [1,2,3,4]
The function is defined as:
@v.parallel(block=True)
def pbands(qs):
i = 1 # This should normally be a loop variable inside the function
valar = [i for j in range(3)]
return 0
Executing this function as
pbands(qs)
yields the error
ValueError: Sorry, cannot pickle code objects with closures
Replacing the i
inside the list comprehension with a literal number or j
, doesn't create an error, but this is no suitable solution, because in the real code i
will be a loop variable.
Is there a way, to get this list comprehension working?