-
Notifications
You must be signed in to change notification settings - Fork 163
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
Reinstall GAP SIGINT handler when Julia is started #3256
base: master
Are you sure you want to change the base?
Reinstall GAP SIGINT handler when Julia is started #3256
Conversation
@@ -659,6 +660,7 @@ void InitBags(UInt initial_size, Bag * stack_bottom, UInt stack_align) | |||
max_pool_obj_size = jl_gc_max_internal_obj_size(); | |||
jl_gc_enable_conservative_gc_support(); | |||
jl_init(); | |||
SyInstallAnswerIntr(); |
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.
Hmm, so let's see, this is the code for SyInstallAnswerIntr
:
void SyInstallAnswerIntr ( void )
{
if ( signal( SIGINT, SIG_IGN ) != SIG_IGN )
{
signal( SIGINT, syAnswerIntr );
siginterrupt( SIGINT, 0 );
}
}
This doesn't do anything if there already is a SIGINT
handler installed, does it? But doesn't Julia install a SIGINT handler? Since I assume you tested this, the answer seems to be no; yet Julia's doc/src/devdocs/init.md
says this:
Finally
sigint_handler()
is hooked up toSIGINT
and callsjl_throw(jl_interrupt_exception)
.
Digging some more into signal-unix.c
also reveals this:
if (sig == SIGINT) {
if (jl_ignore_sigint()) {
continue;
}
else if (exit_on_sigint) {
critical = 1;
}
else {
jl_try_deliver_sigint();
continue;
}
}
Which suggests to me that it does handle SIGINT
, just not via signal()
but rather via sigprocmask
...
(Funny story on the side: On macOS, the relevant C file is signals-mach.c
, which also defines e.g. static void jl_try_deliver_sigint()
, but never calls it, and seems to contain no provisions at all to handle SIGINT
?!? And finally signals-win.c
does have some, but written in a completely different style?!?). Of course libuv
might also be involved somehow?
All of this is to say: I don't quite understand why the above works; and I am slightly worried that it might cause unexpected problems... Like, what happens if our custom SIGINT handler is triggered while we are inside Julia code? Could this leave Julia in an undefined state?
So I guess what I'd like to know is what kind of tests you performed with this modified code... Like, I assume if one starts GAP and loads JuliaInterface in it, but does not use it, everything works fine (Ctrl-C in GAP code enters a break loop). Correct? And what happens if one presses Ctrl-C while Julia code is running? And what happens when one starts Julia and loads GAPJulia, and then presses Ctrl-C, either while Julia code is running, or while GAP code is running? (And I guess ultimately, we also need to think about more deeply nested callchains with ...->GAP code->Julia code->GAP->Julia->...)
None of this is meant to kill of this PR, I simply would like to understand better what it does and why it works, and then perhaps we can put some of it in a comment and/or the commit message?
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.
One problem that you may be running into is that on macOS, Julia does not install a signal handler, but goes directly for the Mach system calls. When they do that, normal signal handling is subsequently ignored. There are ways to insert yourself in the signal handling process in Julia, but I haven't delved too deep into those.
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.
I just realized that signals-mach.c
is included by signals-posix.c
, and now feel dumb for not considering this possibility earlier 🤣
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.
Thanks. This is a very useful first step to improve the SIGINT behaviour.
Works for me runnig GAP code in a GAP that uses julia-gc, in both cases, with JuliaInterface
loaded or not. Ctrl-C
brings me in a brk-loop as usual in GAP.
The TODO becomes obvious when I load JuliaInterface
and start a long running julia-function, then Ctrl-C
does either nothing, or if I type many of them quickly in a row, I get a segfault.
@fingolfin Indeed, I tested it, although, since this was the first quick fix that came to my mind, I did not dig too deeply into it. As @frankluebeck said, yes, it works, and you already pointed out the reason for it. But it seems like it more or less works by accident, so this maybe needs work. I think it would be still a good idea to reinstall the GAP handler. Using When running Julia code, pressing I am planning to replace the |
Quick comment (regarding my plan): Julia handles SIGINT by setting |
@sebasguts I do not understand your statement
Do you mean the current/intended behavior when Julia is called from GAP? Julia without GAP behaves differently, I get an |
This is the intended behaviour after this PR. Currently, the behaviour is as you describe it. After this PR, the behaviour will change to not returning until the execution goes back into GAP code (on whatever level of nesting). I intent to restore the behaviour of having the |
@sebasguts some remarks:
|
With here you mean as a comment to the line I added?
I wanted to keep the changes to GAP as minimal as possible. Without JuliaInterface, GAP does not run Julia code atm, so I thought restoring the previous behaviour would be the easiest way. |
Any updates @sebasguts ? |
@fingolfin @frankluebeck Is there a chance to have this feature (avoid killing GAP on hitting |
@ThomasBreuer I'll look into getting this into shape when I am back from vacation. We could also work on it in Lambrecht. |
3a2534e
to
b5541bd
Compare
Codecov Report
@@ Coverage Diff @@
## master #3256 +/- ##
==========================================
+ Coverage 84.66% 85.16% +0.49%
==========================================
Files 698 696 -2
Lines 345819 344234 -1585
==========================================
+ Hits 292791 293159 +368
+ Misses 53028 51075 -1953
|
Some remarks and update:
|
No description provided.