Opened 15 years ago
Closed 15 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: | N/A | 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)
Change History (7)
comment:1 Changed 15 years ago by
comment:2 Changed 15 years ago by
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:
Cheers, Yi
comment:3 Changed 15 years ago by
Summary: | notebook -- make it so when you send a kill signal to the notebook server it saves state → [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 15 years ago by
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!
comment:5 Changed 15 years ago by
Summary: | [with patch; needs review] notebook -- make it so when you send a kill signal to the notebook server it saves state → [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 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Merged in Sage 3.0.2.alpha1
The python atexit module might help here:
http://docs.python.org/lib/module-atexit.html