Executing shell commands from IPython notebook fails

201 views
Skip to first unread message

Ondřej Čertík

unread,
Sep 8, 2013, 12:49:59 PM9/8/13
to sage-...@googlegroups.com
How to reproduce: type "!ls" (you can use any other command) into a
cell and execute. You will get the following error:

---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-1-b9614390ce83> in <module>()
----> 1 get_ipython().system(u'ls')

/usr/local/sage/sage-5.11/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc
in system_piped(self, cmd)
2215 # a non-None value would trigger :func:`sys.displayhook` calls.
2216 # Instead, we store the exit_code in user_ns.
-> 2217 self.user_ns['_exit_code'] =
system(self.var_expand(cmd, depth=1))
2218
2219 def system_raw(self, cmd):

/usr/local/sage/sage-5.11/local/lib/python2.7/site-packages/IPython/utils/_process_posix.pyc
in system(self, cmd)
153 child = pexpect.spawnb(self.sh, args=['-c',
cmd]) # Pexpect-U
154 else:
--> 155 child = pexpect.spawn(self.sh, args=['-c',
cmd]) # Vanilla Pexpect
156 flush = sys.stdout.flush
157 while True:

/usr/local/sage/sage-5.11/local/lib/python2.7/site-packages/pexpect.pyc
in __init__(self, command, args, timeout, maxread, searchwindowsize,
logfile, env)
325 self.command = command
326
--> 327 command_with_path = which(self.command)
328 if command_with_path == None:
329 raise ExceptionPexpect ('The command was not found
or was not executable: %s.' % self.command)

/usr/local/sage/sage-5.11/local/lib/python2.7/site-packages/pexpect.pyc
in which(filename)
1135 # Special case where filename already contains a path.
1136 if os.path.dirname(filename) != '':
-> 1137 if os.access (filename, os.X_OK) and not os.path.isdir(f):
1138 return filename
1139

UnboundLocalError: local variable 'f' referenced before assignment





It looks like "f" should be renamed to "filename". Not sure if this
pexpect is somehow modified, or why it doesn't work.

Ondrej

William Stein

unread,
Sep 8, 2013, 1:54:34 PM9/8/13
to sage-...@googlegroups.com
We use a very old version of pexpect, because in the newer versions
they made some major design changes that completely kill
performance... at least from my perspective. For sage we want "1
millisecond" latency, not 10-100ms.

I made your bug report

http://trac.sagemath.org/ticket/15178

I also put the line

f = filename

at the top of which and it works to fix the issue -- I'll manually
make this change to all the compute vm's right now, so it'll be fixed
for you, and put it in my instructions for sage upgrades.

-- William

>
> Ondrej
>
> --
> You received this message because you are subscribed to the Google Groups "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-cloud+...@googlegroups.com.
> To post to this group, send email to sage-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-cloud.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cloud/CADDwiVCWHF8tHbXLBVvH-YM_hkN6t_1uW6Y_wBKtHT2ydRMoBw%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org
Reply all
Reply to author
Forward
0 new messages