Starting jupyter console in non interactive mode

231 views
Skip to first unread message

Xavier Orduña

unread,
Dec 7, 2017, 1:23:19 PM12/7/17
to Project Jupyter
HI!

I am trying to run jupyter console using docker and connect to this running console from another client. If I start the container using interactive mode (-ti) and then start the jupyter console, everything is fine.

But if i run jupyter console as the entry point, then I got this exception:

Traceback (most recent call last):
 
File "/usr/local/bin/jupyter-console", line 11, in <module>
    sys
.exit(main())
 
File "/usr/local/lib/python3.5/dist-packages/jupyter_core/application.py", line 266, in launch_instance
   
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
 
File "/usr/local/lib/python3.5/dist-packages/traitlets/config/application.py", line 657, in launch_instance
    app
.initialize(argv)
 
File "<decorator-gen-116>", line 2, in initialize
 
File "/usr/local/lib/python3.5/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
   
return method(app, *args, **kwargs)
 
File "/usr/local/lib/python3.5/dist-packages/jupyter_console/app.py", line 141, in initialize
   
self.init_shell()
 
File "/usr/local/lib/python3.5/dist-packages/jupyter_console/app.py", line 114, in init_shell
    client
=self.kernel_client,
 
File "/usr/local/lib/python3.5/dist-packages/traitlets/config/configurable.py", line 412, in instance
    inst
= cls(*args, **kwargs)
 
File "/usr/local/lib/python3.5/dist-packages/jupyter_console/ptshell.py", line 273, in __init__
   
self.init_prompt_toolkit_cli()
 
File "/usr/local/lib/python3.5/dist-packages/jupyter_console/ptshell.py", line 435, in init_prompt_toolkit_cli
    output
=create_output(true_color=self.true_color),
 
File "/usr/local/lib/python3.5/dist-packages/prompt_toolkit/shortcuts.py", line 126, in create_output
    ansi_colors_only
=ansi_colors_only, term=term)
 
File "/usr/local/lib/python3.5/dist-packages/prompt_toolkit/terminal/vt100_output.py", line 424, in from_pty
   
assert stdout.isatty()
AssertionErrorIntroduïu el codi aquí...

As far as I understand, the error is caused when the jupyter console tries to start the interactive terminal ...

Is there any way to launch the console in the background? without showing the console it self in the terminal.

I checked the options and I am unable to find any of the that suits my needs.

This is the script that starts the kernel:

./push_to_server.sh &
IP
=`ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
#ipython kernel  --control=42005 --shell=42001 --iopub=42002 --hb=42003 --stdin=42004 --ip="$IP" -f /kernel_config.json
#ipython kernel  --ip="$IP" -f /kernel_config.json --log-level=DEBUG
nohup jupyter console  
--ip="$IP" -f /kernel_config.json --log-level=DEBUG --kernel=python3 $*

As you can see, i used directly ipython kernel before, but then to have more than one kernel was complicated.

Thank you very much!

Xavi

Thomas Kluyver

unread,
Dec 7, 2017, 2:57:35 PM12/7/17
to Project Jupyter
Why do you want to start a console in the background? A console is an interactive user interface, so it doesn't really make sense to run it in the background. We can probably figure out a way to do it, but there may be a better way to achieve what you want to do.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/f406fc9a-7235-4b7e-91fe-424496d559e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carlos Córdoba

unread,
Dec 7, 2017, 3:10:00 PM12/7/17
to jup...@googlegroups.com
Xavier, you could start a kernel and connect to it, instead of starting a jupyter console. If you're using ipykernel, that just requires running

    ipython kernel


Cheers,
Carlos

El 07/12/17 a las 14:57, Thomas Kluyver escribió:
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Xavier Orduña

unread,
Dec 7, 2017, 4:01:56 PM12/7/17
to jup...@googlegroups.com
Hi Thomas and Carlos,

Thanks for your ansers, let me clarify a little bit what I am trying to achieve here.

I have a process that needs to run jupyter notebooks (using different kernels, python2, python3, R, etc ...) but since I don't trust those notebooks I want to execute them in a protected environment. I managed to get this working running ipython kernel in the docker container. The process uses a KernelClient to run the notebooks remotely in the container.

This is ok for just one environment, but if want to have many different kernels and languages, I wanted to get advantage of wrapping them using jupyter console. Mainly because when properly installed, jupyter console manages kernel using the --kernel argument which makes the solution pretty clean. This way, in case I want to add new kernels, I just need to configure them in the docker container and launch jupyter console with a different argument.

I know I can run ipython direclty, but it is not clear how to run other kernels directly (for example R).

Thanks a lot!

Xavi


Xavi

-----------------------------
http://www.alcim.net


--
You received this message because you are subscribed to a topic in the Google Groups "Project Jupyter" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jupyter/lJz-z5YGHgc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Thomas Kluyver

unread,
Dec 7, 2017, 4:13:56 PM12/7/17
to Project Jupyter
There should be a command like 'jupyter runkernel' to provide a uniform interface to start different kernels. I'm actually working on jupyter_client at the moment, and a command like this is one of my goals for that work a bit further down the line.
https://github.com/jupyter/jupyter_client/pull/308

In the meantime, you have a few options.

- One is to to run the whole notebook server in the docker container. This is what services like mybinder.org and tmpnb.org do, for instance. The notebook server starts kernels itself inside the container.
- Another is to figure out the commands for the kernels you're using. You can do this by investigating their kernelspecs (see http://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs )
- Using kernel_gateway and nb2kg might be another option
- Finally, there's what you were trying. It's not an unreasonable way to do it, but it does make things like shutting down a kernel trickier. You can probably trick jupyter-console into running by launching it with Ptyprocess ( http://ptyprocess.readthedocs.io/en/latest/ ).

Thomas

Carlos Córdoba

unread,
Dec 7, 2017, 4:25:10 PM12/7/17
to jup...@googlegroups.com
I see Xavier. Then what Thomas is doing will really solve your problem.


Cheers,
Carlos

El 07/12/17 a las 16:13, Thomas Kluyver escribió:
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Xavier Orduña

unread,
Dec 7, 2017, 5:50:45 PM12/7/17
to jup...@googlegroups.com
Hi Thomas,

yes definitely, a command like that is exactly what I am looking for.

In the meantime, maybe it makes more sense to launch it using the kernel specs. And delay support for R language a little bit.

Is there something i can help with to achieve this command?

Thanks,

Xavi


Xavi

-----------------------------
http://www.alcim.net

--
You received this message because you are subscribed to a topic in the Google Groups "Project Jupyter" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jupyter/lJz-z5YGHgc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.

Thomas Kluyver

unread,
Dec 11, 2017, 6:44:00 AM12/11/17
to Project Jupyter
I forgot that I had actually started working on this command a few months ago, then got distracted by other things. I've just done a bit more work on it.

https://github.com/jupyter/jupyter_client/pull/240

Reply all
Reply to author
Forward
0 new messages