kernel spect and how to thest them

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

kernel spect and how to thest them

sandro dentella-2
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
[hidden email]
https://mail.python.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: kernel spect and how to thest them

Thomas Kluyver-2
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:

> 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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/ipython-dev

_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: kernel spect and how to thest them

Alessandro Dentella

Thank you Thomas for the explanations that helped me get to a working
setup.

Rather than settings python interpreter and invoking -m

     "argv": [
         "/home/sandro/.virtualenvs/alma/bin/python3.6",
         "-m",
         "setup_jupyter",  # this imports ipykernel_launcher
         "-f",
         "{connection_file}",
         "--ext",
         "django_extensions.management.notebook_extension"

I ended with this setup:

     "argv": [
         "/home/sandro/alma/bin/ipython",
         "kernel",
         "-f",
         "{connection_file}",
         "--ext",
         "django_extensions.management.notebook_extension"

In my setup (I use buildout) bin/ipython is a script with the path
explicitely declared and running:

   import IPython

   if __name__ == '__main__':
       sys.exit(IPython.start_ipython())


The reason I had to change this way is that ipykernel_launcher works
only if called directly (as is the cas with -m flag since the code is
in the "If __name__ == '__main__'" branch.

If my operation is for some reason incorrect, please let me know. I
got the impression the script jupyter should be used rather than
ipython...


sandro
_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/ipython-dev