How can I know if Jupyter is running?

1,018 views
Skip to first unread message

Ivan Andrus

unread,
Jan 16, 2016, 11:53:07 PM1/16/16
to sage-devel
To adapt to the soon-to-be-default Jupyter notebook in Sage, I’m updating the Mac app to launch either SageNB or Jupyter depending on a preference. Unfortunately, I can’t figure out how to determine if Jupyter is already running at all, let alone in a given directory or on what port. I can scrape the log if I’m the one who started the server, but I would like to check if they have started it some other way. Does anyone know how to do that?

Also, I’m thinking of making ~/Documents/Sage the default directory to run Jupyter in. Does that seem reasonable to everyone?

-Ivan

William Stein

unread,
Jan 17, 2016, 2:22:26 AM1/17/16
to sage-devel
On Sat, Jan 16, 2016 at 8:53 PM, Ivan Andrus <darth...@gmail.com> wrote:
> To adapt to the soon-to-be-default Jupyter notebook in Sage, I’m updating the Mac app to launch either SageNB or Jupyter depending on a preference. Unfortunately, I can’t figure out how to determine if Jupyter is already running at all, let alone in a given directory or on what port. I can scrape the log if I’m the one who started the server, but I would like to check if they have started it some other way. Does anyone know how to do that?
>

I hit the same problem. I wrote a script that tracks the pid, etc.,
for Jupyter, which is used by SMC extensively:
https://github.com/sagemathinc/smc/blob/master/src/smc_pyutil/smc_pyutil/jupyter_notebook.py

As it says in the comments in the scripts, some things I do in there
are *HIDEOUS*. I'm not happy with it at all in terms of being "good
code". It does work OK though, and is fairly battle tested.

> Also, I’m thinking of making ~/Documents/Sage the default directory to run Jupyter in. Does that seem reasonable to everyone?
>

In SMC, I start the Jupyter server in $HOME. Then when users open
the file browser in Jupyter, they see their home directory, and can
browse to any of their files.

-- William

> -Ivan
>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To post to this group, send email to sage-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.



--
William (http://wstein.org)

Volker Braun

unread,
Jan 17, 2016, 3:12:22 AM1/17/16
to sage-devel
IMHO the app should just start and manage its own jupyter server; Launch it on startup and shut it down when the app is closed. The notebook server doesn't fork into the background so its trivial to just keep a single process, no need for a pidfile.

If the user wants to launch a separate server (maybe with different options) by hand then he/she should be allowed to.

PS:
* Always use subprocess over os.system
* Jupyter will autoincrement the port if it is in use, don't rely on it using the given --port
* Race conditions with ports, pids, and filenames are unlikely but often exploitable security issues.

Volker Braun

unread,
Jan 17, 2016, 3:15:06 AM1/17/16
to sage-devel
PS: The Jupyter file browser jails the user into the startup directory, so we really have to run it in $HOME

Ivan Andrus

unread,
Jan 18, 2016, 7:23:24 AM1/18/16
to sage-...@googlegroups.com
On Jan 17, 2016, at 1:12 AM, Volker Braun <vbrau...@gmail.com> wrote:
>
> IMHO the app should just start and manage its own jupyter server; Launch it on startup and shut it down when the app is closed. The notebook server doesn't fork into the background so its trivial to just keep a single process, no need for a pidfile.

Well, I disagree, but it sounds like it’s the only option.

> If the user wants to launch a separate server (maybe with different options) by hand then he/she should be allowed to.
>
> PS:
> * Always use subprocess over os.system

I was planning to use NSTask. :-)

> * Jupyter will autoincrement the port if it is in use, don't rely on it using the given —port

Right.

> * Race conditions with ports, pids, and filenames are unlikely but often exploitable security issues.

I’ll keep that in mind.

-Ivan
Reply all
Reply to author
Forward
0 new messages