[IPython-dev] ERROR can not use fork(), exec(), dup2() to communicate with child process

Andy Davidson Andy at SantaCruzIntegration.com
Thu Oct 2 19:17:34 EDT 2014


I want to write a notebook that receives data from another process. Bellow
is my python code. It forks a child process and reads the data from the
child using a pipe. This code works if I run it in python. When I try to
execute from iPython notebook I get the following error. Any idea what the
problems is ?

If pipes do not work, can I use a socket? The other process would send me
data by writing, my notebook needs behave like a server.

Any comments or suggestions would be greatly appreciated.



P.s. I am running headless on a remote machine and use an ssh tunnel to run
the notebook from my local browser. My other notebooks works fine

[ec2-user at ip-172-31-14-107 ~]$ IPYTHON_OPTS="notebook --pylab inline
--no-browser --port=7000" /root/spark/bin/pyspark

/root/spark/conf/spark-env.sh: line 21: ulimit: open files: cannot modify
limit: Operation not permitted

[NotebookApp] Using existing profile dir:

[NotebookApp] Serving notebooks from /home/ec2-user

[NotebookApp] The IPython Notebook is running at:

[NotebookApp] Use Control-C to stop this server and shut down all kernels.

[NotebookApp] Using MathJax from CDN:

[NotebookApp] Kernel started: 71f07d5c-2db1-465f-9d86-da29f8711a0b

[NotebookApp] Connecting to: tcp://

[NotebookApp] Connecting to: tcp://

[NotebookApp] Connecting to: tcp://

[IPKernelApp] To connect another client to this kernel, use:

[IPKernelApp] --existing kernel-71f07d5c-2db1-465f-9d86-da29f8711a0b.json

Assertion failed: ok (bundled/zeromq/src/mailbox.cpp:79)

[NotebookApp] Kernel 71f07d5c-2db1-465f-9d86-da29f8711a0b failed to respond
to heartbeat

import sys
import os

def child(pipeout):
    os.dup2(pipeout, sys.stdout.fileno())
    os.execlp("./test.sh", "abc")

def parent():
    pipein, pipeout = os.pipe()
    if os.fork() == 0:
        counter = 1
        pipein = os.fdopen(pipein)
        while True:
            json = pipein.readline()[:-1]
            print 'parent: %s' % (json)


$ cat test.sh





echo $script_name $args

echo "XYZ: "$XYZ

echo "PATH: "$PATH

echo "current directory: $current"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141002/aefaa3fc/attachment.html>

More information about the IPython-dev mailing list