Skip to content

NameError: name 'time' is not defined #39

Description

@FlorinAndrei

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:

p-tqdm==1.3.3
tqdm==4.61.1
pathos==0.2.8
multiprocess==0.70.12.2

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions