The following code works perfectly:
from multiprocessing import Pool
import time
values = list(range(10))
def print_time_and_value(value):
print(time.time(), value)
if __name__ == '__main__':
p = Pool(4)
p.map(print_time_and_value, values)
but when I change the "multiprocessing" import to the "multiprocess" library:
from multiprocess import Pool
it raises the following error during execution:
Traceback (most recent call last):
File "test.py", line 13, in <module>
p.map(print_time_and_value, values)
File "C:\Users\User\Anaconda3_64bits\lib\site-packages\multiprocess\pool.py", line 268, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "C:\Users\User\Anaconda3_64bits\lib\site-packages\multiprocess\pool.py", line 657, in get
raise self._value
NameError: name 'time' is not defined
I can't use multiprocessing since I have to use unpicklable objects later on my main application, so I have to use multiprocess, which has dill serialization.
I have noticed that putting the "time" import inside the "print_time_and_value" function instead of the global scope solves this issue, but this behavior is a bit weird. As it is a fork of multiprocessing, I had guessed it would work the same way.
I'm using Python 3.7.0, multiprocess module is version 0.70.7; running on 64 bits Anaconda environment, Windows 10.