Skip to content

Issue accessing modules and variables defined outside function on Windows with Pool.map #137

@astrofrog

Description

@astrofrog

When using multiprocess.Pool, I am getting a different behavior on Mac/Linux compared to Windows - on Windows the following example does not work:

In [1]: import os                                                                                                                                                                                                                               
In [2]: def example(filename):
...:     return os.path.abspath(filename)                                                                              
In [3]: from multiprocess import Pool                                                                                                                                                                                                           
In [4]: p = Pool()
 ...: p.map(example, ['a.jpg', 'b.jpg', 'c.jpg'])                                                                     
---------------------------------------------------------------------------                                             
RemoteTraceback                          
 Traceback (most recent call last)                                             
RemoteTraceback:                                                                                                        
"""                                                                                                                     
Traceback (most recent call last):                                                                                        
File "C:\Users\Thomas Robitaille\.conda\envs\py311\Lib\site-packages\multiprocess\pool.py", line 125, in worker          
 result = (True, func(*args, **kwds))                                                                                                    
^^^^^^^^^^^^^^^^^^^                                                                                   
File "C:\Users\Thomas Robitaille\.conda\envs\py311\Lib\site-packages\multiprocess\pool.py", line 48, in mapstar           
return list(map(*args))                                                                                                        
^^^^^^^^^^^^^^^^                                                                                              
 File "<ipython-input-2-36e5e27f9cec>", line 2, in example                                                             
NameError: name 'os' is not defined                                                                                    
 """

But this does appear to work properly on Mac and Linux by default. Is this expected behavior or a bug? Do I need to redefine all imports and variables inside the function?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions