# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1210489882 25200
# Node ID 19807feec3063d1c6193d858d64ad877611d033b
# Parent b457320c962f891261a575d3497de1bb6a417b1f
trac #2359 -- notebook -- make it so when you send a kill signal to the notebook server it saves state
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.
diff -r b457320c962f -r 19807feec306 sage/server/notebook/run_notebook.py
a
|
b
|
def notebook_twisted(self, |
166 | 166 | # WARNING -- Do not edit this file! It is autogenerated each time |
167 | 167 | # the notebook(...) command is executed. |
168 | 168 | #################################################################### |
| 169 | from twisted.internet import reactor |
169 | 170 | |
170 | 171 | # Now set things up and start the notebook |
171 | 172 | import sage.server.notebook.notebook |
… |
… |
worksheet.init_sage_prestart(twist.noteb |
181 | 182 | worksheet.init_sage_prestart(twist.notebook.get_server(), twist.notebook.get_ulimit()) |
182 | 183 | |
183 | 184 | import signal, sys, random |
| 185 | def save_notebook(): |
| 186 | print "Saving notebook..." |
| 187 | twist.notebook.save() |
| 188 | reactor.stop() |
| 189 | print "Notebook cleanly saved." |
| 190 | |
184 | 191 | def my_sigint(x, n): |
185 | | twist.notebook.save() |
| 192 | save_notebook() |
186 | 193 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
187 | | print "(Notebook cleanly saved. Press control-C again to exit.)" |
| 194 | |
188 | 195 | |
189 | 196 | signal.signal(signal.SIGINT, my_sigint) |
190 | 197 | |
… |
… |
try: |
193 | 200 | import gnutls.connection |
194 | 201 | gnutls.connection.CERT_REQUEST = 0 |
195 | 202 | except OSError: |
196 | | print "Note: GNUTLS not available." |
| 203 | print "Note: GNUTLS not available." |
| 204 | |
197 | 205 | |
198 | 206 | ## Authentication framework (ported from Knooboo) |
199 | 207 | from twisted.web2 import log, server, channel |
… |
… |
s = strports.service('%s', factory) |
223 | 231 | s = strports.service('%s', factory) |
224 | 232 | %s |
225 | 233 | s.setServiceParent(application) |
| 234 | |
| 235 | reactor.addSystemEventTrigger('before', 'shutdown', save_notebook) |
| 236 | |
226 | 237 | """%(notebook_opts, sagetex_path, not require_login, |
227 | 238 | os.path.abspath(directory), strport, open_page)) |
228 | 239 | |
… |
… |
s.setServiceParent(application) |
235 | 246 | if secure and not quiet: |
236 | 247 | print "There is an admin account. If you do not remember the password," |
237 | 248 | print "quit the notebook and type notebook(reset=True)." |
238 | | cmd = 'sage -twistd --pidfile="%s"/twistd.pd -ny "%s"/twistedconf.tac'%(directory, directory) |
| 249 | cmd = 'sage -twistd --pidfile="%s"/twistd.pid -ny "%s"/twistedconf.tac'%(directory, directory) |
239 | 250 | if fork: |
240 | 251 | return pexpect.spawn(cmd) |
241 | 252 | else: |