-
-
Notifications
You must be signed in to change notification settings - Fork 499
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 spyx_tmp()
cleanup.
#39201
base: develop
Are you sure you want to change the base?
Fix spyx_tmp()
cleanup.
#39201
Conversation
Documentation preview for this PR (built with commit 9669a86; changes) is ready! 🎉 |
I think this works because It should be fine but can you please leave a comment explaining why |
For some reason, a new behaviour of python 3.13 [0] causes the `TemporaryDirectory()` in `sage.misc.temporary_file.spyx_tmp()` to be deleted on child exit, which causes trouble with parallel doctesting [1]. We rewrite `spyx_tmp()` using `tmp_dir()`, which doesn't have this problem, see [2]. [0] python/cpython#114279 [1] sagemath#39188 (comment) [2] sagemath#39188 (comment)
1e5947a
to
9669a86
Compare
I don't think so:
The only reason you got away with this is because on python 3.12 and earlier python objects are not finalized when a child exits, skipping the side effect of the
Ok, done. |
While we're at it,
This docstring is very wrong. Looks like the implementation has changed long ago. (but the |
atexit.register(lambda: d.cleanup()) | ||
# We don't use `tempfile.TemporaryDirectory()` here because it | ||
# will be cleaned up on child exit (e.g. for parallel testing) | ||
# For some reason this doesn't affect the `TemporaryDirectory` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using tempfile.TemporaryDirectory()
works just fine for me, so this comment may not be completely correct (however, it is not cleaned up on exit of the parent process)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm.. so you mean TemporaryDirectory()
is not cleaning up on program exit in general, or only in sage.misc.temporary_file.spyx_tmp()
? What about sage.misc.temporary_file.TMP_DIR_FILENAME_BASE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only on spyx_tmp()
. The TMP_DIR_FILENAME_BASE
one is cleaned up correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, there seems to be something fragile about using TemporaryDirectory()
on a local variable that is meant to survive its function. There are no clear rules about when this object will be destroyed (apparently the lambda: d.cleanup()
grabs a reference that stays in the atexit hook, but I'm not sure if the lambda takes a strong reference).
I guess the "right" way to acomplish what was intended here might be to store d
in the global variable, and not just d.name
.
I… still don't understand why this patch may work.
Though it sound like a good idea to put all the temporary stuff into the same place anyway. |
No, because
|
IIUC, But my problem is not the atexit hook removing the directory. It's the weakref.finalize for the Arguably, a bug in |
For some reason, a new behaviour of python 3.13 [0] causes the
TemporaryDirectory()
insage.misc.temporary_file.spyx_tmp()
to be deleted on child exit, which causes trouble with parallel
doctesting [1].
We rewrite
spyx_tmp()
usingtmp_dir()
, which doesn't have thisproblem, see [2].
[0] python/cpython#114279
[1] #39188 (comment)
[2] #39188 (comment)
In addition, use
sage_
prefix for the main temporary directory.📝 Checklist