Skip to content
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

Exit Sage gracefully upon SIGHUP #13908

Closed
jdemeyer opened this issue Jan 4, 2013 · 16 comments
Closed

Exit Sage gracefully upon SIGHUP #13908

jdemeyer opened this issue Jan 4, 2013 · 16 comments

Comments

@jdemeyer
Copy link

jdemeyer commented Jan 4, 2013

Change the signal handling code to allow a graceful forced exit of Sage. "graceful" meaning that code is interrupted and the normal exit handlers are run. This graceful exit is not guaranteed to work, code which is currently not interruptible would not be exited.

This might be used by the doctesting framework to handle timeouts.

This patch also improves interrupt debugging:

  1. Different debug levels, set in a C file such that not everything needs to be recompiled when changing the debug level.
  2. Show time between signal received and exception raised.

Apply: attachment: 13908_terminate.patch

Depends on #13748
Depends on #13946

Component: c_lib

Author: Jeroen Demeyer

Reviewer: Volker Braun

Merged: sage-5.7.beta2

Issue created by migration from https://trac.sagemath.org/ticket/13908

@jdemeyer jdemeyer added this to the sage-5.6 milestone Jan 4, 2013
@jdemeyer jdemeyer self-assigned this Jan 4, 2013
@jdemeyer

This comment has been minimized.

@jdemeyer jdemeyer changed the title Exit Sage gracefully upon SIGHUP Exit Sage gracefully upon SIGHUP/SIGTERM Jan 11, 2013
@jdemeyer
Copy link
Author

Author: Jeroen Demeyer

@jdemeyer
Copy link
Author

Changed dependencies from #13748 to #13748, #13946

@vbraun
Copy link
Member

vbraun commented Jan 20, 2013

comment:6

Sounds good to me.

@vbraun
Copy link
Member

vbraun commented Jan 20, 2013

Reviewer: Volker Braun

@jdemeyer
Copy link
Author

comment:8

See sage-devel.

@jdemeyer
Copy link
Author

comment:9

Since the main motivation is to have some way of gracefully terminating Sage, I'm handling only SIGHUP now, not SIGTERM.

@jdemeyer jdemeyer changed the title Exit Sage gracefully upon SIGHUP/SIGTERM Exit Sage gracefully upon SIGHUP Jan 28, 2013
@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link
Author

Attachment: 13908_no_SIGTERM.patch.gz

@jdemeyer
Copy link
Author

comment:11

Attachment: 13908_terminate.patch.gz

@jdemeyer

This comment has been minimized.

@vbraun
Copy link
Member

vbraun commented Jan 28, 2013

comment:13

Hmm I didn't see any discussion on sage-devel about SIGTERM but getting started with just catching SIGHUP is fine, too.

@jdemeyer
Copy link
Author

@jdemeyer
Copy link
Author

Merged: sage-5.7.beta2

@stumpc5
Copy link
Contributor

stumpc5 commented Feb 23, 2013

comment:16

I was running a moinmoin wiki with sage. With this patch applied, that doesn't work anymore because of the new interruption handling in sage.ext._init_csage:

When running the wiki using

$ sage wikiserver.py

and importing sage.all.* therein, I get the following error:

    from sage.all import *
  File "/home/stumpc5/progs/sage-5.7/devel/sage-main/build/sage/all.py", line 59, in <module>
    _init_csage()
  File "c_lib.pyx", line 41, in sage.ext.c_lib._init_csage (sage/ext/c_lib.c:569)
    
ValueError: signal only works in main thread

The issue seems to be solved when I comment out the signal in _init_csage.

Question: Is there a (reasonable and finite) way to fix this issue properly? Can something serious go wrong if I comment these lines out?

Thanks, Christian

@jdemeyer
Copy link
Author

comment:17

Replying to @stumpc5:

Can something serious go wrong if I comment these lines out?

Not very serious. Interrupt handling might be a bit messed up, in particular some interrupts (CTRL-C) might be seen twice: once by the default Python handler (raise KeyboardInterrupt) and once by the special Sage handler (written in C).

The line

signal.signal(signal.SIGINT, sage_python_check_interrupt)

is mainly used to ensure that only the Sage signal handler is used.

But this will certainly have no consequences beyond interrupt handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants