Import statements and multiprocessing

Nicholas Cole nicholas.cole at gmail.com
Tue Jan 30 10:54:30 EST 2018


Dear List,

I have a strange problem on python 3.6.1

I am using the multiprocessing function to parallelize an expensive
operation, using the multiprocessing.Pool() and Pool.map() functions.

The function I am passing to map calls a function in another file
within the same model.  And that file has a

from .some_file_in_the_package import *

line at the top.

However, in each function called in that file, I seem to need to put
an explicit important statement buried within the function in order
for the code to work:

def some_function():
    from .some_file_in_the_package import ThisObject

It is as if in the worker processes created by Pool.map() the from .
import * directive is being completely ignored.

With the explicit import statements everything works as expected.

What could be going wrong?

Best wishes,

Nicholas



More information about the Python-list mailing list