2

Before I open an IPython notebook, I'd like to check whether it is in a directory that is already being served by a server process. The goal is to connect to that server instead of launching yet another server for the same directory.

Background: I often work with IPython notebooks in several different directories, and since one server can only handle one directory hierarchy, I have to launch several separate notebook servers. As far as I know this cannot be avoided unless I move all my notebooks into the same directory hierarchy, right? But at least I want to avoid launching more servers than necessary. If I could check for the existence of a suitable server (and get the connection ID), I could connect to it instead of launching a new one.

alexis
  • 48,685
  • 16
  • 101
  • 161
  • I don't think you need to run a separate iPython notebook server for working on another directory. You can always change your working directory or work with absolute file paths to access files in other directories. – joemar.ct May 11 '14 at 11:16
  • 1
    @joemar, can you be more specific? From everything I've read (e.g., the comments to [this answer](http://stackoverflow.com/a/18901898/699305)), you can specify a different directory when you start a notebook server, but you can't change the working directory during the lifetime of the server-- and there's no way to pass an absolute path to a running server, that I know of. Hence this question. – alexis May 11 '14 at 15:57
  • I'm not sure we understand each other correctly. Maybe you mean something different; but what I meant is that, the iPython notebook is just like any normal Python interpreter, you can change the current working directory using `os.chdir(path_to_dir)`. – joemar.ct May 11 '14 at 16:26
  • Looks like we do not understand each other. Please read my question more carefully and if you can answer it, I would really like to hear more. – alexis May 11 '14 at 16:58
  • 1
    As of IPython 2.x you can navigate, i.e. change the active folder, in the dashboard (see [release notes](http://ipython.org/ipython-doc/stable/whatsnew/version2.0.html)). Hence, in many cases it is sufficient to start a single kernel instance at some root directory and open notebooks in various different folders. – Jakob May 12 '14 at 21:11
  • @Jakob, good point, thanks! As long as I start notebook in a sufficiently high directory, I can reach all the subdirectories. But is there a recommended commandline method for asking a running server for a file in a subdirectory? – alexis May 14 '14 at 10:31

1 Answers1

3

Running ipython notebook help or ipython notebook -h gives the answer. Who knew?

Subcommands

Subcommands are launched as ipython-script.py cmd [args]. For information on using subcommand 'cmd', do: ipython cmd -h.

list  
    List currently running notebook servers in this profile.

Curiously the above list is both incomplete (the subcommand help is not mentioned) and incorrect: The correct invocation is ipython notebook list, not ipython list.

% ipython notebook list
alexis
  • 48,685
  • 16
  • 101
  • 161