[IPython-User] Starting kernel outside the main thread
Wed Feb 27 16:24:02 CST 2013
recently I have been experimenting with embedding an ipython kernel inside a
C++ program for inspecting/debugging purposes.
For reasons that probably don't matter, embedding the kernel doesn't happen
in the main thread and you tend to hit "ValueError: signal only works in
main thread" exceptions from multiple places in the code.
My very naive understanding is that the signal registering is done so that
Control-C will shut down the kernel cleanly. In my particular example I
don't have any interactive terminal attached to the kernel so that there is
no way for me to hit Control-C.
I just went for the simplest solution I could see which was monkey-patching
signal.signal and wrapping it inside a try except. A simplified gist
illustrating the issue I had and a possible work-around is available at
Am I going to be bitten me pretty hard later down the line if I go down this
signal monkey-patching route? Is there a better way to support embedding
kernel outside the main thread?
Finally could this work-around be used to have non-blocking kernels, i.e.
with the gist above in mind you could start multiple kernels in different
threads (I guess you would need to customise the default kernel-<pid>.json
naming to get a different connection file for each thread)?
More information about the IPython-User