Calling a wrapped in a decorator method concurrently with tqdm.contrib.concurent.process_map inside a Class raises AttributeError: 'Class' object has no attribute 'wrapper' error.
I understand that I have a potential workaround of the task by means of multiprocessing.pool.map. However, since I found process_map really handy when handling progress bars with concurrency, I was hoping if anyone could help me avoiding this error while keeping process_map and the decorator.
Input
from tqdm.contrib.concurrent import process_map
def error_handle(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as exc:
print(f"ERROR IN function {func.__name__} with exception {exc}")
return wrapper
class Foo:
def __init__(self) -> None:
pass
def bar_wrapper(self):
process_map(self.bar, 100*[0], max_workers=10)
@error_handle
def bar(self, a):
pass
obj = Foo()
obj.bar_wrapper()
Output
[...]
AttributeError: 'Foo' object has no attribute 'wrapper'
I've tried defining the method inside the class itself as a non-static and static class and neither worked out.