-
Notifications
You must be signed in to change notification settings - Fork 419
Fix tqdm callback garbage collection #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tqdm callback garbage collection #1463
Conversation
Calling `close()` on `TqdmCallback.tqdm` reliably results in an exception on interpreter exit. Debug prints show that in such cases, the value of `tqdm` is not, as expected, the progress bar instance, but rather the `no_op` bound method, which does not have a `close` attribute. This change checks attribute existence of `close()` first before calling it on the class. Checking this way does not require a `tqdm` import.
|
Repro (scoped to from fsspec.callbacks import TqdmCallback
from lakefs_spec import LakeFSFileSystem
def upload():
fs = LakeFSFileSystem()
res2 = fs.get_file(".sandbox/mnist.py", "quickstart/main/mnist.py", precheck=False, callback=TqdmCallback())
print(f"LakeFS backend result: {res2}")
if __name__ == "__main__":
upload()Results in: Adding the mentioned print statements |
|
However, the progress bar is not shown in the traceback, which indicates that it is successfully garbage collected before the callback itself is. I'd very much welcome another opinion on this. |
|
I have a proposal in #1460 to make callbacks a context manager. Ideally, we should not depend on |
|
Sweet! If you could also migrate the tqdm closing to the proposed |
|
@skshetry , I leave it up to you whether to include the small change here in your PR. I'd be happy to merge this otherwise. |
|
Please feel free (to merge). I have no issues with this PR. |
Calling
close()onTqdmCallback.tqdmreliably results in an exception on interpreter exit. Debug prints show that in such cases, the value oftqdmis not, as expected, the progress bar instance, but rather theno_opbound method, which does not have acloseattribute.This change checks attribute existence of
close()first before calling it on the class. Checking this way does not require atqdmimport.