-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
27 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import contextlib | ||
|
||
import joblib | ||
from tqdm import tqdm | ||
|
||
|
||
@contextlib.contextmanager | ||
def tqdm_joblib(tqdm_object): | ||
"""Context manager to patch joblib to report into tqdm progress bar given as argument""" | ||
|
||
class TqdmBatchCompletionCallback(joblib.parallel.BatchCompletionCallBack): | ||
def __call__(self, *args, **kwargs): | ||
tqdm_object.update(n=self.batch_size) | ||
return super().__call__(*args, **kwargs) | ||
|
||
old_batch_callback = joblib.parallel.BatchCompletionCallBack | ||
joblib.parallel.BatchCompletionCallBack = TqdmBatchCompletionCallback | ||
try: | ||
yield tqdm_object | ||
finally: | ||
joblib.parallel.BatchCompletionCallBack = old_batch_callback | ||
tqdm_object.close() |