Hi,

there is a bug in pexpect. When I did couple changes in Sage, so that
it works when the binary is renamed from "sage" to "spd", I got this
traceback when running notebook():

$ ./spd
-----------------------------------------------------------------------------
| Source Python Distribution, Version 3.4.1.beta4, Release Date: 2009-04-15 |
| Type notebook() for the GUI, and license() for information.               |
-----------------------------------------------------------------------------
In [1]: from sage.server.notebook.notebook_object import notebook
In [2]: notebook()
The notebook files are stored in: /home/ondrej/.spd//sage_notebook
**************************************************
*                                                *
* Open your web browser to http://localhost:8000 *
*                                                *
**************************************************
Traceback (most recent call last):
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/twisted/application/app.py",
line 614, in run
    runApp(config)
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/twisted/scripts/twistd.py",
line 23, in runApp
    _SomeApplicationRunner(config).run()
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/twisted/application/app.py",
line 330, in run
    self.application = self.createOrGetApplication()
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/twisted/application/app.py",
line 416, in createOrGetApplication
    application = getApplication(self.config, passphrase)
--- <exception caught here> ---
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/twisted/application/app.py",
line 427, in getApplication
    application = service.loadApplication(filename, style, passphrase)
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/twisted/application/service.py",
line 368, in loadApplication
    application = sob.loadValueFromFile(filename, 'application', passphrase)
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/twisted/persisted/sob.py",
line 214, in loadValueFromFile
    exec fileObj in d, d
  File "sage_notebook/twistedconf.tac", line 19, in <module>

  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/sage/server/notebook/worksheet.py",
line 156, in init_sage_prestart
    _a_sage = initialized_sage(server, ulimit)
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/sage/server/notebook/worksheet.py",
line 118, in initialized_sage
    S._start(block_during_init=False)
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/sage/interfaces/expect.py",
line 450, in _start
    self._expect = pexpect.spawn(cmd, logfile=self.__logfile)
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/pexpect.py",
line 326, in __init__
    command_with_path = which(self.command)
  File 
"/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/pexpect.py",
line 1133, in which
    if os.access (filename, os.X_OK) and not os.path.isdir(f):
exceptions.UnboundLocalError: local variable 'f' referenced before assignment

Failed to load application: local variable 'f' referenced before assignment

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)

/home/ondrej/.spd/<ipython console> in <module>()

/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/sage/server/notebook/notebook_object.pyc
in __call__(self, *args, **kwds)
    163     """
    164     def __call__(self, *args, **kwds):
--> 165         return self.notebook(*args, **kwds)
    166
    167     notebook = run_notebook.notebook_twisted

/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/sage/server/notebook/run_notebook.pyc
in notebook_twisted(self, directory, port, address, port_tries,
secure, reset, accounts, require_login, server_pool, ulimit, timeout,
open_viewer, sagetex_path, start_path, fork, quiet)
    274     if open_viewer:
    275         "Open viewer automatically isn't fully implemented.
You have to manually open your web browser to the above URL."
--> 276     return run(port)
    277
    278

/home/ondrej/ext/spd/spd/spd1/local/lib/python2.5/site-packages/sage/server/notebook/run_notebook.pyc
in run(port)
    258             e = os.system(cmd)
    259         if e == 256:
--> 260             raise socket.error
    261         return True
    262         # end of inner function run

error:
In [3]:




The bug is in this code in local/lib/python2.5/site-packages/pexpect.py:

def which (filename):
    """This takes a given filename; tries to find it in the environment path;
    then checks if it is executable.
    This returns the full path to the filename if found and executable.
    Otherwise this returns None.
    """
    # Special case where filename already contains a path.
    if os.path.dirname(filename) != '':
        if os.access (filename, os.X_OK) and not os.path.isdir(filename):
            return filename

The fix is trivial, just change

-        if os.access (filename, os.X_OK) and not os.path.isdir(f):
+        if os.access (filename, os.X_OK) and not os.path.isdir(filename):


and all starts working. I don't understand why and how I triggered it
(e.g. how can this work in Sage?), but in any case, this is clearly a
bug in pexpect.


Ondrej

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to