Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13908 closed enhancement (fixed)

Exit Sage gracefully upon SIGHUP

Reported by: Jeroen Demeyer Owned by: Jeroen Demeyer
Priority: major Milestone: sage-5.7
Component: c_lib Keywords:
Cc: Merged in: sage-5.7.beta2
Authors: Jeroen Demeyer Reviewers: Volker Braun
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #13748, #13946 Stopgaps:

Status badges

Description (last modified by Jeroen Demeyer)

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: 13908_terminate.patch

Attachments (2)

13908_no_SIGTERM.patch (4.7 KB) - added by Jeroen Demeyer 10 years ago.
13908_terminate.patch (17.4 KB) - added by Jeroen Demeyer 10 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 Changed 10 years ago by Jeroen Demeyer

Description: modified (diff)
Summary: Exit Sage gracefully upon SIGHUPExit Sage gracefully upon SIGHUP/SIGTERM

comment:2 Changed 10 years ago by Jeroen Demeyer

Authors: Jeroen Demeyer
Status: newneeds_review

comment:3 Changed 10 years ago by Jeroen Demeyer

Dependencies: #13748#13748, #13946

comment:4 Changed 10 years ago by Jeroen Demeyer

Status: needs_reviewneeds_work

comment:5 Changed 10 years ago by Jeroen Demeyer

Status: needs_workneeds_review

comment:6 Changed 10 years ago by Volker Braun

Reviewers: Volker Braun
Status: needs_reviewpositive_review

Sounds good to me.

comment:7 Changed 10 years ago by Jeroen Demeyer

Milestone: sage-5.6sage-5.7

comment:8 Changed 10 years ago by Jeroen Demeyer

Status: positive_reviewneeds_work

See sage-devel.

comment:9 Changed 10 years ago by Jeroen Demeyer

Summary: Exit Sage gracefully upon SIGHUP/SIGTERMExit Sage gracefully upon SIGHUP

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

comment:10 Changed 10 years ago by Jeroen Demeyer

Description: modified (diff)

Changed 10 years ago by Jeroen Demeyer

Attachment: 13908_no_SIGTERM.patch added

Changed 10 years ago by Jeroen Demeyer

Attachment: 13908_terminate.patch added

comment:11 Changed 10 years ago by Jeroen Demeyer

Description: modified (diff)

comment:12 Changed 10 years ago by Jeroen Demeyer

Status: needs_workneeds_review

comment:13 Changed 10 years ago by Volker Braun

Status: needs_reviewpositive_review

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

comment:15 Changed 10 years ago by Jeroen Demeyer

Merged in: sage-5.7.beta2
Resolution: fixed
Status: positive_reviewclosed

comment:16 Changed 10 years ago by Christian Stump

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

comment:17 in reply to:  16 Changed 10 years ago by Jeroen Demeyer

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.

Note: See TracTickets for help on using tickets.