Ticket #2359: sage-2359.patch

File sage-2359.patch, 2.8 KB (added by boothby, 13 years ago)

Removed polynomial garbage

  • sage/server/notebook/run_notebook.py

    # 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, 
    166166# WARNING -- Do not edit this file!   It is autogenerated each time
    167167# the notebook(...) command is executed.
    168168####################################################################
     169from twisted.internet import reactor
    169170
    170171# Now set things up and start the notebook
    171172import sage.server.notebook.notebook
    worksheet.init_sage_prestart(twist.noteb 
    181182worksheet.init_sage_prestart(twist.notebook.get_server(), twist.notebook.get_ulimit())
    182183
    183184import signal, sys, random
     185def save_notebook():
     186    print "Saving notebook..."
     187    twist.notebook.save()
     188    reactor.stop()
     189    print "Notebook cleanly saved."
     190   
    184191def my_sigint(x, n):
    185     twist.notebook.save()
     192    save_notebook()
    186193    signal.signal(signal.SIGINT, signal.SIG_DFL)
    187     print "(Notebook cleanly saved. Press control-C again to exit.)"
     194   
    188195   
    189196signal.signal(signal.SIGINT, my_sigint)
    190197
    try: 
    193200    import gnutls.connection
    194201    gnutls.connection.CERT_REQUEST = 0
    195202except OSError:
    196     print "Note: GNUTLS not available."
     203    print "Note: GNUTLS not available."
     204
    197205
    198206## Authentication framework (ported from Knooboo)
    199207from twisted.web2 import log, server, channel
    s = strports.service('%s', factory) 
    223231s = strports.service('%s', factory)
    224232%s
    225233s.setServiceParent(application)
     234
     235reactor.addSystemEventTrigger('before', 'shutdown', save_notebook)
     236
    226237"""%(notebook_opts, sagetex_path, not require_login,
    227238     os.path.abspath(directory), strport, open_page))
    228239
    s.setServiceParent(application) 
    235246        if secure and not quiet:
    236247            print "There is an admin account.  If you do not remember the password,"
    237248            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)
    239250        if fork:
    240251            return pexpect.spawn(cmd)
    241252        else: