Am getting this error when using the pool.map(funct, iterable)
:
AttributeError: __exit__
No Explanation, only stack trace to the pool.py file within the module.
using in this way:
with Pool(processes=2) as pool:
pool.map(myFunction, mylist)
pool.map(myfunction2, mylist2)
I suspect there could be a problem with the picklability (python needs to pickle
, or transform list data into byte stream) yet I'm not sure if this is true or if it is how to debug.
EDIT: new format of code that produces this error :
def governingFunct(list):
#some tasks
def myFunction():
# function contents
with closing(Pool(processes=2)) as pool:
pool.map(myFunction, sublist)
pool.map(myFunction2, sublist2)
ERROR PRODUCED:
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
In Python 2.x and 3.0, 3.1 and 3.2,
multiprocessing.Pool()
objects are not context managers. You cannot use them in awith
statement. Only in Python 3.3 and up can you use them as such. From the Python 3multiprocessing.Pool()
documentation:For earlier Python versions, you could use
contextlib.closing()
, but take into account this'll callpool.close()
, notpool.terminate()
. Terminate manually in that case:or create your own
terminating()
context manager:with
statement is for object that have__enter__
and__exit__
functions, i.e. Context Manager Typesmultiprocessing.Pool
is not Context Manager Type. try do the following: