-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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: Allow calls to exit
from within exit hooks
#32502
RFC: Allow calls to exit
from within exit hooks
#32502
Conversation
exit
from within exit hooksexit
from within exit hooks
One of the consequences of this pull request is that this code: atexit(() -> exit(0))
atexit(() -> exit(5))
atexit(() -> exit(10))
exit(15) will cause Julia to exit with exit code I'm not sure that this behavior makes sense. Is this what we want? |
Closing in favor of #32253 |
FWIW, I think we should do both |
Reopened! |
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.
There seems like a lot of tests here. How long do these take? It doesn't seem like it should need that many to fully cover the cases.
I like this change; it's very elegant. For reference, posix seems to allow atexit handlers to call |
I've deleted a bunch of tests. There are relatively few tests now, but I think we still cover all the cases. |
Bump @vtjnash Take a look and let me know if I’ve addressed your concerns with regards to the number of tests. |
Yep. Could I ask you to rebase and push an updated copy? We had some CI issues on this run (from stuff on master at the time), and I'd like to check that it's green before merging. |
Done! |
""" => 1, | ||
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
""" | ||
atexit(() -> println("No error")) |
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.
Would you mind making a quick followup PR to make these silent during a normal test run?
atexit(() -> println("No error")) | |
atexit(() -> "No error") |
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.
Yeah!
Fixes #31743
This is an alternative to pull request #32253. I personally prefer the approach in #32253.
This pull request allows calls to
exit(n)
from within exit hooks registered withBase.atexit
.From the updated docstring for
Base.atexit
:exit(n)
, in which case Julia will exit withexit code
n
(instead of the original exit code). If more than one exit hookcalls
exit(n)
, then Julia will exit with the exit code corresponding to thelast called exit hook that calls
exit(n)
. (Because exit hooks are called inLIFO order, "last called" is equivalent to "first registered".)
I have included some tests. They are located in the
test/atexit.jl
file.