Closed yusanshi closed 3 years ago
I have been thinking about adding a replace() method to make transitions like this easier. However, I think for your use case, you can add leave=False
and then close the counter when you're finished. You may also find using position 1 will give you better results than position 0.
import time
import enlighten
import numpy as np
batches = np.random.uniform(size=(20, 20))
def train(batch):
time.sleep(0.1)
manager = enlighten.get_manager()
for epoch in range(10):
pbar = manager.counter(desc=str(epoch), total=len(batches), position=1, leave=False)
for batch in pbar(batches):
train(batch)
pbar.close()
Additionally, in this use case, you'll find you don't need to specify the position at all, though perhaps in your project you do. You can also close implicitly using a context manager:
for epoch in range(10):
with manager.counter(desc=str(epoch), total=len(batches), leave=False) as pbar:
for batch in pbar(batches):
train(batch)
Thanks for your timely reply. leave=False
does the trick.
Is your feature request related to a problem? Please describe. Sometimes I want to create several counters in the same specified position, but it will raise
Counter position {} is already occupied.
error. So I would like to know how can I release a counter and then create another in the same position.An example:
Describe the solution you'd like A function to destroy a counter as well as its position.
Describe alternatives you've considered A function to reset a counter (reset its escape time and current count value).