Opened 7 years ago

Closed 7 years ago

#2359 closed enhancement (fixed)

[with patch; positive review] notebook -- make it so when you send a kill signal to the notebook server it saves state

Reported by: was Owned by: boothby
Priority: major Milestone: sage-3.0.2
Component: notebook Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

Kill signal does this

2008/03/01 01:10 -0500 [-] Received SIGTERM, shutting down.
2008/03/01 01:10 -0500 [-] (Port 8000 Closed)
2008/03/01 01:10 -0500 [-] Stopping factory <twisted.web2.channel.http.HTTPFactory instance at 0x2a41530>
2008/03/01 01:10 -0500 [-] Main loop terminated.
2008/03/01 01:10 -0500 [-] Server Shut Down.

Control C does this

2008/03/01 01:12 -0500 [-] (Notebook cleanly saved. Press control-C again to exit.)

We should change the notebook so it catches the kill and saves the notebook cleanly. I have no idea how to do this. Maybe some sort of "hook" into Twisted. If anybody knows twisted or reads the docs and figures this out, post here!

Attachments (1)

sage-2359.patch (2.8 KB) - added by boothby 7 years ago.
Removed polynomial garbage

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by jason

The python atexit module might help here:

http://docs.python.org/lib/module-atexit.html

comment:2 Changed 7 years ago by yi

If you want to do things the twisted way, here is something that should work:

reactor.addSystemEventTrigger('before', 'shutdown', f)

f is a function you want to be called BEFORE the reactor shuts down. Here is some more documentation about how to properly use this feature:

http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IReactorCore.html#addSystemEventTrigger

Cheers,
Yi

http://yiqiang.org

comment:3 Changed 7 years ago by was

  • Summary changed from notebook -- make it so when you send a kill signal to the notebook server it saves state to [with patch; needs review] notebook -- make it so when you send a kill signal to the notebook server it saves state

The attached patch fixes the issues:

   1. I followed Yi's suggestion which worked like a charm.
   2. As a bonus I also fixed the "have to hit control-c twice to stop the notebook server" crap. Now
      it stops just fine with one single control-c.
   3. I changed twistd.pd to twistd.pid  -- it's a typo since it's supposed to be a pin id.

comment:4 Changed 7 years ago by yi

A couple of comments:

1) As far as I can tell the last bit of the patch (involving polynomials) has nothing to do with this issue. Could you explain what that does?

2) Is save_notebook() only used on shutdown? Isn't it possible that in the future, someone would want to call save_notebook while the notebook is running? If that's true, you probably do not want to call reactor.stop() in save_notebook unless you're _certain_ that save_notebook() is the last thing you want to do.

Besides that this patch looks great!

Changed 7 years ago by boothby

Removed polynomial garbage

comment:5 Changed 7 years ago by boothby

  • Summary changed from [with patch; needs review] notebook -- make it so when you send a kill signal to the notebook server it saves state to [with patch; positive review] notebook -- make it so when you send a kill signal to the notebook server it saves state

works for me -- I uploaded a cleaned up patch.

comment:6 Changed 7 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from new to closed

Merged in Sage 3.0.2.alpha1

Note: See TracTickets for help on using tickets.