jupyter / jupyter_client

Jupyter protocol client APIs
https://jupyter-client.readthedocs.io
BSD 3-Clause "New" or "Revised" License
386 stars 285 forks source link

Starting a new kernel under Windows 10 loops indefinitely #220

Open tcpie opened 7 years ago

tcpie commented 7 years ago

Hi everybody,

I am developing a front-end for jupyter kernels in C++ using Qt as my GUI framework. My application works fine under Linux (Ubuntu 16.10 x86_64, with Anaconda3). However, when I try to run under Windows (10, x86_64, with Anaconda3), the program starts up, and then re-launches (forks?) itself indefinitely. Very annoying.

I am able to reproduce the issue with the following minimal C code: (note that you should change the PY_SITE_PACKAGES_PATH define to fit your system).

#include <stdio.h>
#include <Python.h>

#ifdef _WIN32
#define PY_SITE_PACKAGES_PATH "D:/Anaconda3/Lib"
#else
#define PY_SITE_PACKAGES_PATH "/usr/share/anaconda3/lib/python3.5/site-packages"
#endif

int main(void)
{
    Py_Initialize();

    PyObject *syspath = PySys_GetObject("path");

    PyObject* pName = PyUnicode_FromString(PY_SITE_PACKAGES_PATH);
    int ret = PyList_Insert(syspath, 0, pName);

    ret = PyRun_SimpleString("import jupyter_client");
    ret = PyRun_SimpleString("jupyter_client.manager.start_new_kernel(kernel_name='python3')");

    printf("Return value: %i\n", ret);
    return ret;
}

Under Linux, the program output is:

Return value: 0

Under Windows, the output is:

File "", line 1, in File "D:\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 433, in start_new_kernel kc.wait_for_ready(timeout=startup_timeout) File "D:\Anaconda3\lib\site-packages\jupyter_client\blocking\client.py", line 63, in wait_for_ready raise RuntimeError("Kernel didn't respond in %d seconds" % timeout) RuntimeError: Kernel didn't respond in 60 seconds Return value: -1 Traceback (most recent call last): File "", line 1, in File "D:\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 433, in start_new_kernel kc.wait_for_ready(timeout=startup_timeout) File "D:\Anaconda3\lib\site-packages\jupyter_client\blocking\client.py", line 63, in wait_for_ready raise RuntimeError("Kernel didn't respond in %d seconds" % timeout) RuntimeError: Kernel didn't respond in 60 seconds Return value: -1

Repeating indefinitely. I checked under Windows to see if my kernel spec was OK. jupyter kernelspec list returns:

Available kernels: python3 D:\Anaconda3\lib\site-packages\ipykernel\resources

Under Windows, I can also start a Jupyter notebook session, using the jupyter notebook command, without any issue. I'm not sure what I'm doing wrong here.

tcpie commented 7 years ago

OK, I can fix the issue by running ipython kernel install. However, it is still not clear to me why I need to do this, since jupyter notebook is working fine. Moreover, I doubt the program effectively looping itself (without me programming in a for or while loop!) is proper behaviour (in the case of my GUI program, the GUI window keeps popping up, clogging the computer).

minrk commented 7 years ago

It is a bit odd that installing the kernelspec would change the resulting behavior. That suggests that perhaps a different kernelspec is found. Maybe it has to do with the way you are changing PY_SITE_PACKAGES_PATH to a location that is not actually a site-packages directory.