Ticket #2779: trac_2779-sagenb-error-message.patch

File trac_2779-sagenb-error-message.patch, 1.7 KB (added by timdumol, 12 years ago)

Outputs a clearer error message (see comment)

  • sagenb/notebook/run_notebook.py

    #2779 Error message for notebook server already running is misleading.
    
    diff -r 6ad36d1d4099 sagenb/notebook/run_notebook.py
    a b  
    2020    protocol = 'ssl'
    2121
    2222# System libraries
    23 import getpass, os, shutil, socket
     23import getpass, os, shutil, socket, sys
     24from exceptions import SystemExit
     25
     26from twisted.python.runtime import platformType
    2427
    2528from sagenb.misc.misc import (DOT_SAGENB, print_open_msg, find_next_available_port)
    2629
     
    287290        if secure and not quiet:
    288291            print "There is an admin account.  If you do not remember the password,"
    289292            print "quit the notebook and type notebook(reset=True)."
    290         cmd = 'twistd --pidfile="%s"/twistd.pid -ny "%s"/twistedconf.tac'%(directory, directory)
     293
     294        pidfile = os.path.join(directory, 'twistd.pid')
     295        cmd = 'twistd --pidfile="%s" -ny "%s"' % (pidfile, os.path.join(directory, 'twistedconf.tac'))
     296
     297        # Check if a Twistd PID exists in the given directory
     298        if platformType != 'win32':
     299            from twisted.scripts._twistd_unix import checkPID
     300            try:
     301                checkPID(pidfile)
     302            except SystemExit as e:
     303                pid = int(open(pidfile).read())
     304                if str(e).startswith('Another twistd server is running,'):
     305                    sys.exit("""\
     306Another Sage Notebook server is running, PID %d.
     307
     308Please either stop the old server or run the new server in a different directory.
     309""" % pid)
    291310        if fork:
    292311            import pexpect
    293312            return pexpect.spawn(cmd)