You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code breaks with NameError: name 'time' is not defined:
import time
from tqdm.auto import tqdm
from p_tqdm import p_map, p_umap, p_imap, p_uimap
numbers = list(range(0, 1000))
def heavy_processing(number):
time.sleep(0.05)
output = number + 1
return output
results = p_map(heavy_processing, numbers)
print(results)
Error message:
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Users\flori\AppData\Roaming\Python\Python38\site-packages\multiprocess\pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "C:\Users\flori\AppData\Roaming\Python\Python38\site-packages\pathos\helpers\mp_helper.py", line 15, in <lambda>
func = lambda args: f(*args)
File "<ipython-input-2-a99c335b4b30>", line 5, in add
NameError: name 'time' is not defined
"""
The above exception was the direct cause of the following exception:
NameError Traceback (most recent call last)
<ipython-input-4-1bbf104dda25> in <module>
----> 1 added = p_map(add, l1, l2)
~\AppData\Roaming\Python\Python38\site-packages\p_tqdm\p_tqdm.py in p_map(function, *iterables, **kwargs)
58 ordered = True
59 generator = _parallel(ordered, function, *iterables, **kwargs)
---> 60 result = list(generator)
61
62 return result
~\AppData\Roaming\Python\Python38\site-packages\p_tqdm\p_tqdm.py in _parallel(ordered, function, *iterables, **kwargs)
47 map_func = getattr(pool, map_type)
48
---> 49 for item in tqdm(map_func(function, *iterables), total=length, **kwargs):
50 yield item
51
~\AppData\Roaming\Python\Python38\site-packages\tqdm\notebook.py in __iter__(self)
252 def __iter__(self):
253 try:
--> 254 for obj in super(tqdm_notebook, self).__iter__():
255 # return super(tqdm...) will not catch exception
256 yield obj
~\AppData\Roaming\Python\Python38\site-packages\tqdm\std.py in __iter__(self)
1176
1177 try:
-> 1178 for obj in iterable:
1179 yield obj
1180 # Update and possibly print the progressbar.
~\AppData\Roaming\Python\Python38\site-packages\multiprocess\pool.py in next(self, timeout)
866 if success:
867 return value
--> 868 raise value
869
870 __next__ = next # XXX
NameError: name 'time' is not defined
However, this works fine - the difference being, I've passed the time module as a name to my function:
import time
from tqdm.auto import tqdm
from p_tqdm import p_map, p_umap, p_imap, p_uimap
numbers = list(range(0, 1000))
def heavy_processing(number, time=time):
time.sleep(0.05)
output = number + 1
return output
results = p_map(heavy_processing, numbers)
print(results)
I have Windows 10, Jupyter Notebook, Python 3.8.8, and these packages:
I am facing the same issue with a similar usage. I have imported the time module, and inside a function running in a couple parallel processes, I am attempting a time.sleep(1). When that line is reached in each process, I get the NameError: name 'time' is not defined error you're reporting.
I'm also running Jupyter on Win 10, so I suspect a similar root cause. Did you uncover a solution?
This code breaks with
NameError: name 'time' is not defined
:Error message:
However, this works fine - the difference being, I've passed the time module as a name to my function:
I have Windows 10, Jupyter Notebook, Python 3.8.8, and these packages:
Is it a bug with p-tqdm? Or with one of the other modules? (in which case I will move this bug report to the appropriate repo)
The text was updated successfully, but these errors were encountered: