I would like to hide the creation of a rich Progress() bars and associated tasks inside a class. I thought the following will work, but it doesn't. The progress bar doesn't render.
class Klass:
@contextmanager
def progress(self):
p = Progress()
self.Iter = p.add_task('Iterations')
yield p
p.remove_task(self.Iter)
del self.Iter
obj = Klass()
with obj.progress() as p:
for _ in range(100):
sleep(0.1)
p.advance(obj.Iter, 1)
Note that this is simplified example. In my real application, the Klass has a lot of other stuff and I need several tasks.