-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Add remove_atexit
keyword argument to mktempdir(parent)
#32335
RFC: Add remove_atexit
keyword argument to mktempdir(parent)
#32335
Conversation
remove_on_exit
keyword argument to mktempdir(parent)
remove_on_exit
keyword argument to mktempdir(parent)
Co-Authored-By: Alex Arslan <ararslan@comcast.net>
Done! |
Seems okay to me in general, but I think a stronger test would be nice. Something like generating a temp directory name in the main process, spinning up a child process that does |
Done. I run a child process that (1) creates a temp directory, (2) tests that it exists (throwing an error if it does not), and (3) prints the name of the temp directory to STDOUT. The parent process runs the child process, reads the temp directory from STDOUT, and then tests that it no longer exists. |
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.
Neat, I like this idea!
Maybe in a followup-PR we should do it for open
and mktemp
also (which could try to map to FILE_FLAG_DELETE_ON_CLOSE
/ O_TMPFILE
, where applicable)?
Can this be merged? |
Note from triage: would be nice to synchronize terminology more and not use both "at exit" and "on exit". The argument could be called |
Done. I've renamed |
remove_on_exit
keyword argument to mktempdir(parent)
remove_atexit
keyword argument to mktempdir(parent)
Triage is kind of stuck on this one on account of two things:
These two things seem to combine to lead to a near future where we have a proliferation of functions with one of the most unfortunate keyword argument names I've ever found. Triage spent a significant time trying to come up with something better but we couldn't come up with anything. |
Related to an idea Stefan had, we could make the keyword just called |
And if we had |
How about something short like |
Although, if #32831 gets merged, then |
That is a pretty good point. |
I would be ok with |
My only issue with |
True. At least with |
True. And frankly, |
Let me know if/when you want to go with the Specifically:
|
|
f(path) = atexit(()->f(path))
mktempdir(path, atexit=f) |
Here's a radical idea: always do this, unconditionally. I.e. don't provide an option, just always set an |
I realize that might be a slight performance issue since adding a lot of atexit hooks could be problematic, but we could instead implement this by keeping a list of temporary paths to ensure the deletion of temp paths and using a single atexit handler to clean up all of them. Then, of course, I start to think about "what if the list of temp paths gets really huge?" at which point I think about scanning it before the end of the process if it's too long when adding a new path to it and clearing out any paths that are already deleted so we don't have to remember them. |
That's an interesting idea, I think that would make a lot of sense. If you're doing |
That is not a crazy idea at all!
This would be easy to implement. We have some length cutoff |
Yeah, I've already got a PR worked up for this. I'm stuck on a yak shave because it broke the precompile script and to fix the precompile script I need a |
Superseded by #32851. Thanks for the impetus, @DilumAluthge! |
Description
This pull request adds a
remove_atexit
keyword argument to themktempdir(parent)
method.Old method signature:
mktempdir(parent=tempdir(); prefix=$(repr(temp_prefix)))
New method signature:
mktempdir(parent=tempdir(); prefix=$(repr(temp_prefix)), remove_atexit=false)
If
remove_atexit
istrue
, then we add anatexit
exit hook that will remove the temporary directory when Julia exits.If
remove_atexit
isfalse
(default), then the current behavior is preserved. Therefore, this change is backwards compatible.Rationale
Currently, you can use the
mktempdir(fn::Function, parent=tempdir(); prefix=temp_prefix)
method to create a temporary directory, apply the functionfn
, and then remove the temporary directory. However, this requires that you have a functionfn
that contains all of the code that you want to run while the temporary directory is available. You may instead want to create a temporary directory, keep it available for the entire duration of the Julia program, and only delete it when Julia exits. Currently, if you want this functionality, you have to create theatexit
exit hook yourself. This pull request makes this easier by creating the exit hook for you.