Created
May 31, 2019 13:58
-
-
Save joshlk/11a3a3f127becbf81647a85f15835612 to your computer and use it in GitHub Desktop.
Progress bar for Python Trio tasks using tqdm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import trio | |
import tqdm | |
class TrioProgress(trio.abc.Instrument): | |
def __init__(self, total, notebook_mode=False, **kwargs): | |
if notebook_mode: | |
from tqdm import tqdm_notebook as tqdm | |
else: | |
from tqdm import tqdm | |
self.tqdm = tqdm(total=total, **kwargs) | |
def task_exited(self, task): | |
self.tqdm.update(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment