[IPython-dev] kernel spect and how to thest them

Thomas Kluyver takowl at gmail.com
Sat Feb 16 05:46:39 EST 2019


Hi Sandro,

> I'd like to bettere understand "argv" list. It's the arguments passed to
what exactely?

To the operating system. It spawns a process with subprocess.Popen(), and
those are the arguments for it. It's like running the command from a shell.

> -m and --ext are for python/ipython, who interprets -f?

The -f flag is for ipykernel, defined here:
https://github.com/ipython/ipykernel/blob/34ca17011c1e79f65290b88f1deb18ac03e142af/ipykernel/kernelapp.py#L58

> How can I debug what's wrong and particularly is there a way to start
that particular kernel, based on those kernel spec alone?

Normally those 'restarting kernel' messages come with a traceback saying
what went wrong. I'm not sure why they don't in your case.

You can run a kernel through Jupyter by running 'jupyter kernel --kernel
your-kernel-name' (where your-kernel-name is whatever you called the folder
with kernel.json in). Alternatively, you can set the environment variables
in your shell, join up argv with spaces, and run that in the shell.

On Fri, 15 Feb 2019 at 23:10, Alessandro Dentella <sandro.dentella at gmail.com>
wrote:

> Hi,
>
> I'd like to bettere understand "argv" list. It's the arguments passed
> to what exactely? -m and --ext are for python/ipython, who interprets -f?
>
> The setup
> =========
>
> I have a django project whit a std virtualenv with a working kernel
> defined as follows:
>
> {
>     "env": {
>            "DJANGO_SETTINGS_MODULE": "web.settings",
>            "PYTHONPATH":
> "$PYTHONPATH:/misc/src/hg/thunder/siti/alma/django" },
>     "argv": [
>         "/home/sandro/.virtualenvs/alma/bin/python3.6",
>         "-m",
>         "ipykernel_launcher",
>         "-f",
>         "{connection_file}",
>         "--ext",
>         "django_extensions.management.notebook_extension"
>     ],
>     "display_name": "Alma ",
>     "language": "python"
> }
>
> From a jupyter lab I can connect to that and it just works fine.
>
> In my normal setup I use buildout that means I have an "empty"
> vitualenv and a scipt that initializes the sys.path. So I tried to
> modify the configuration as follows:
>
> {
>     "env": {
>            "DJANGO_SETTINGS_MODULE": "web.settings",
>            "PYTHONPATH":
> "$PYTHONPATH:/misc/src/hg/thunder/siti/alma/django/env" },
>     "argv": [
>         "/home/sandro/.virtualenvs/alma/bin/python3.6",
>         "-m",
>         "setup_jupyter",
>         "-f",
>         "{connection_file}",
>         "--ext",
>         "django_extensions.management.notebook_extension"
>     ],
>     "display_name": "Alma 2",
>     "language": "python"
> }
>
> Where setup_jupiter is in PYTHONPATH and uses site.addsitedir():
>
>    import os
>    import site
>    site.addsitedir(os.path.dirname(__file__))
>    import ipykernel_launcher
>
> Question
> ========
>
> But this modified kernel spec does not work (sys.path it's correclty
> setup due to a custom path.pth)
>
> Jupiter lab (run in a different virtualenv) complains:
>
>    [I 20:07:27.618 LabApp] Kernel started:
> 11cc7c35-b88b-4f87-ad42-bdf85f28c352
>    [I 20:07:28.230 LabApp] KernelRestarter: restarting kernel (2/5), new
> random ports
>    [I 20:07:31.236 LabApp] KernelRestarter: restarting kernel (3/5), new
> random ports
>    [I 20:07:34.244 LabApp] KernelRestarter: restarting kernel (4/5), new
> random ports
>    [W 20:07:37.249 LabApp] KernelRestarter: restart failed
>
>
> How can I debug what's wrong and particularly is there a way to start
> that particular kernel, based on those kernel spec alone?
>
> Sandro
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at python.org
> https://mail.python.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20190216/52b1969e/attachment.html>


More information about the IPython-dev mailing list