-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got ProgressManager working for schemecreate
- Loading branch information
1 parent
a6f5788
commit 6bcc6d5
Showing
5 changed files
with
130 additions
and
64 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import time | ||
|
||
from tqdm import tqdm | ||
|
||
|
||
class ProgressTracker(tqdm): | ||
def __init__(self, process, iterable, *args, **kwargs): | ||
self.process = process | ||
super().__init__(iterable, *args, **kwargs) | ||
|
||
|
||
class ProgressManager: | ||
_subprocess: None | ProgressTracker | ||
|
||
def __init__(self): | ||
self._status = None | ||
self._subprocess = None | ||
|
||
def n(self) -> int | None: | ||
if self._subprocess: | ||
return self._subprocess.n | ||
return None | ||
|
||
def total(self) -> int | None: | ||
if self._subprocess: | ||
return self._subprocess.total | ||
return None | ||
|
||
def process(self) -> str | None: | ||
if self._subprocess: | ||
return self._subprocess.process | ||
return None | ||
|
||
def create_sub_progress(self, iter, process, *args, **kwargs) -> ProgressTracker: | ||
"""Create a progress tracker""" | ||
self._subprocess = ProgressTracker( | ||
*args, iterable=iter, process=process, **kwargs, desc=process | ||
) | ||
return self._subprocess | ||
|
||
|
||
if __name__ == "__main__": | ||
pm = ProgressManager() | ||
|
||
print(pm.process(), pm.n(), pm.total()) | ||
|
||
for _ in pm.create_sub_progress(iter=range(10), process="test"): | ||
print(_) | ||
print(pm.process(), pm.n(), pm.total()) | ||
time.sleep(0.1) | ||
|
||
print(pm.n()) |
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