swansonk14 / p_tqdm

Parallel processing with progress bars
MIT License
457 stars 44 forks source link

Global variables not visible by p_tqdm module #10

Closed kbeary33 closed 4 years ago

kbeary33 commented 4 years ago

I can't get this module to work with other modules in the called function. For example, the following code returns an error:

import time
from p_tqdm import p_map

def _foo(my_number):
   square = my_number * my_number
   time.sleep(1)
   return square 

if __name__ == '__main__':
   r = p_map(_foo, list(range(0, 30)))

ultiprocess.pool.RemoteTraceback: """ Traceback (most recent call last): File "C:\Users\kb\AppData\Local\Continuum\anaconda3\lib\site-packages\multiprocess\pool.py", line 121, in worker result = (True, func(*args, *kwds)) File "C:\Users\kb\AppData\Local\Continuum\anaconda3\lib\site-packages\pathos\helpers\mp_helper.py", line 15, in func = lambda args: f(args) File "c:/Test p_tqdm.py", line 6, in _foo time.sleep(1) NameError: name 'time' is not defined """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "c:/Test p_tqdm.py", line 10, in r = p_map(_foo, list(range(0, 30))) File "C:\Users\kb\AppData\Local\Continuum\anaconda3\lib\site-packages\p_tqdm\p_tqdm.py", line 86, in p_map result = list(iterator) File "C:\Users\kb\AppData\Local\Continuum\anaconda3\lib\site-packages\p_tqdm\p_tqdm.py", line 75, in _parallel for item in tqdm(map_func(function, *arrays), total=num_iter, kwargs): File "C:\Users\kb\AppData\Local\Continuum\anaconda3\lib\site-packages\tqdm\std.py", line 1081, in iter for obj in iterable: File "C:\Users\kb\AppData\Local\Continuum\anaconda3\lib\site-packages\multiprocess\pool.py", line 748, in next raise value NameError: name 'time' is not defined**

ziofil commented 4 years ago

your example works for me

swansonk14 commented 4 years ago

Hi @kbeary33, your example also works for me. Please let me know if you're still having problems and I can reopen the issue.

BlueSkyLT commented 1 year ago

The same is happening to me. I am working with Python 3.8. The OP's example doesn't work for me either.

Hi @kbeary33, your example also works for me. Please let me know if you're still having problems and I can reopen the issue.