Skip to content
This repository

Notebook kernel crash when specifying --notebook-dir on commandline #886

Closed
fwerner opened this Issue October 17, 2011 · 8 comments

3 participants

Felix Werner Min RK Fernando Perez
Felix Werner

Hi,

I start a notebook server like this:

$ ipython notebook --notebook-dir="/home/fwerner/Documents/Notebooks" --pylab=inline

After loading a notebook in my browser, the kernel dies instantly. This is related to the notebook-dir alias, which you can see from the traceback---here's the full console output:

$ ipython notebook --notebook-dir="/home/fwerner/Documents/Notebooks" --pylab=inline --log-level=DEBUG --debug
[IPythonNotebookApp] Config changed:
[IPythonNotebookApp] {'Application': {'log_level': 10}, 'IPKernelApp': {'pylab': u'inline'}, 'NotebookManager': {'notebook_dir': u'/home/fwerner/Documents/Notebooks'}}
[IPythonNotebookApp] Using existing profile dir: u'/home/fwerner/.config/ipython/profile_default'
[IPythonNotebookApp] Searching path [u'/home/fwerner/Development/ipython', u'/home/fwerner/.config/ipython/profile_default'] for config files
[IPythonNotebookApp] Attempting to load config file: ipython_config.py
[IPythonNotebookApp] Config file ipython_config.py not found
[IPythonNotebookApp] Attempting to load config file: ipython_notebook_config.py
[IPythonNotebookApp] Config file not found, skipping: ipython_notebook_config.py
[IPythonNotebookApp] The port 8888 is already in use, trying another random port.
[IPythonNotebookApp] The IPython Notebook is running at: http://127.0.0.1:8904
WARNING:root:404 GET /static/mathjax/MathJax.js?config=TeX-AMS_HTML (127.0.0.1) 0.44ms
[IPythonNotebookApp] Kernel started: e493215c-54f4-49a9-b8a9-a158ea272965
[IPythonNotebookApp] Connecting to: tcp://127.0.0.1:48262
[IPythonNotebookApp] Connecting to: tcp://127.0.0.1:49537
[IPythonNotebookApp] Connecting to: tcp://127.0.0.1:37896
WARNING: Unrecognized alias: 'notebook-dir', it will probably have no effect.Traceback (most recent call last):
  File "", line 1, in 
  File "IPython/zmq/ipkernel.py", line 777, in main
    app.initialize()
  File "IPython/zmq/ipkernel.py", line 710, in initialize
    super(IPKernelApp, self).initialize(argv)
  File "IPython/zmq/kernelapp.py", line 279, in initialize
    super(KernelApp, self).initialize(argv)
  File "IPython/core/application.py", line 306, in initialize
    self.parse_command_line(argv)
  File "IPython/config/application.py", line 406, in parse_command_line
    config = loader.load_config()
  File "IPython/config/loader.py", line 575, in load_config
    self._convert_to_config()
  File "IPython/config/loader.py", line 664, in _convert_to_config
    sub_parser.load_config(self.extra_args)
  File "IPython/config/loader.py", line 496, in load_config
    self._exec_config_str(lhs, rhs)
  File "IPython/config/loader.py", line 347, in _exec_config_str
    exec exec_str in locals(), globals()
  File "", line 1
SyntaxError: can't assign to operator

The SyntaxError is thrown by the (assembled) statement

self.config.notebook-dir=u'/home/fwerner/Documents/Notebooks'

It seems to me that IPython shouldn't even try to run statements like this---or at least catch the SyntaxError and warn the user. But I think the real issue is that the notebook-dir alias isn't known at this point. Maybe it also doesn't have to be known, and the commandline argument should have been swallowed at an earlier stage?

Unfortunately, I'm not familiar enough with the codebase to proceed further.

Cheers,
Felix

Fernando Perez
Owner

Actually, @minrk today fixed up that particular error, but the --notebook-dir option remains broken. In master, giving it produces an empty landing page even if the directory pointed to contains notebooks. And clicking the 'new notebook' button crashes the whole thing with:

ERROR:root:Uncaught exception GET /new (127.0.0.1)
HTTPRequest(protocol='http', host='127.0.0.1:8888', method='GET', uri='/new', version='HTTP/1.1', remote_ip='127.0.0.1', body='', headers={'Accept-Language': 'en-us,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Host': '127.0.0.1:8888', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1', 'Accept-Charset': 'UTF-8,*', 'Connection': 'keep-alive', 'Referer': 'http://127.0.0.1:8888/', 'If-None-Match': '"5b68dcdf6f18fcfcc2be970584c3c45957e4abde"'})
Traceback (most recent call last):
  File "/home/fperez/usr/opt/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/web.py", line 954, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
  File "/home/fperez/usr/opt/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/web.py", line 1667, in wrapper
    return method(self, *args, **kwargs)
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/html/notebook/handlers.py", line 77, in get
    notebook_id = self.application.notebook_manager.new_notebook()
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/html/notebook/notebookmanager.py", line 225, in new_notebook
    with open(path,'w') as f:
IOError: [Errno 2] No such file or directory: u'~/ipython/ipython/docs/examples/notebooks/Untitled0.ipynb'
ERROR:root:500 GET /new (127.0.0.1) 1.12ms

Flagging as critical for 0.12, thanks for the report!

Felix Werner

Hi again,

sorry for the trouble, I fixed the issue without realising it. Please take a look at this commit:
fwerner/ipython@23abedf

Cheers,
Felix

Fernando Perez
Owner

Actually that change has already been made in master, see:

https://github.com/ipython/ipython/blob/master/IPython/frontend/html/notebook/notebookapp.py#L226

But the issue I pointed above remains, currently the --notebook-dir flag is indeed broken.

Felix Werner

Sorry for the confusion---I only saw your comment after posting mine.

I cannot reproduce the issue you mentioned with the current master. Listing the notebooks in the specified directory works as expected, also creating/renaming/saving do.

Fernando Perez
Owner

Ah, now I see. The crash only occurs in a very particular call form:

ipnb --notebook-dir=/home/fperez/tmp

works, and

ipnb --notebook-dir ~tmp

also works, but

ipnb --notebook-dir=~tmp

produces the crash. The reason is that in this last form, because of the = sign, the shell doesn't expand the ~ and neither do we. Since it's a reasonable call form, we just need to call expanduser(path) on the input path before processing it when passed with an = sign, or at least fail with a more informative error message than an iternal server error.

But I'm downgrading the severity of this issue, as it's now clear that the problem is only with parsing a very particular call form. thanks for the feedback!

Min RK
Owner

@fperez should the parser just always pass strings through expanduser on strings? It would appear that's what argparse is doing, so it makes sense to match.

Fernando Perez
Owner
Min RK minrk closed this issue from a commit October 24, 2011
Min RK Don't let invalid aliases crash IPython
e.g. `ipython --foo-bar=5` would raise a SyntaxError parsing the commmand-line, because `self.config.foo-bar=5` would be evaluated.

Syntax Errors on the rhs were already protected, but they could get into the lhs via the alias syntax.

closes gh-886
11bca29
Min RK minrk closed this in 11bca29 October 24, 2011
Min RK
Owner

home expansion and invalid-arg crashing both fixed.

Brian E. Granger ellisonbg referenced this issue from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.