[IPython-dev] Kernel race condition on Mac OS

Paul Butler paulgb at gmail.com
Sun Sep 15 12:29:45 EDT 2013


Hi,

I'm developing with the kernel APIs and I've encountered a race condition.
It seems to be a Mac-specific thing; I haven't been able to reproduce it on
Ubuntu or CentOS.

The following code demonstrates the problem. It's also available as a
gist<https://gist.github.com/paulgb/6572133>.
The call to iopub.get_msg will (usually) fail unless sleep(1) is
uncommented.

from IPython.kernel import KernelManager
from time import sleep


def racecondition():
    km = KernelManager()
    km.start_kernel()


    kc = km.client()
    kc.start_channels()


    iopub = kc.iopub_channel
    shell = kc.shell_channel

    #sleep(1)


    shell.execute('print "hello world"')
    print shell.get_msg(timeout=1)
    print iopub.get_msg(timeout=1)

if __name__ == '__main__':
    racecondition()

By experimenting with where the sleep(1) call can go, it seems that
the kernel subprocess takes a few milliseconds to be ready to accept
input.


Is there any call to check if the kernel is ready?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20130915/cfcaee8c/attachment.html>


More information about the IPython-dev mailing list