[IPython-User] Starting ipython kernel outside main thread
Loïc Estève
loic.esteve@ymail....
Thu Feb 28 01:20:55 CST 2013
Hi,
sorry if this message reaches the mailing twice, I subscribed to ipython-
user after sending this and am not 100% sure this will hit the mailing list
eventually. Anyway here was the original message:
I 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 https://gist.github.com/lesteve/5052267.
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 embed 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)?
Cheers,
Loïc
More information about the IPython-User
mailing list