[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


Hi



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.



Thanks



Andy



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:
u'/home/ec2-user/.ipython/profile_default'

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

[NotebookApp] The IPython Notebook is running at: http://127.0.0.1:7000/

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

[NotebookApp] Using MathJax from CDN:
http://cdn.mathjax.org/mathjax/latest/MathJax.js

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

[NotebookApp] Connecting to: tcp://127.0.0.1:54119

[NotebookApp] Connecting to: tcp://127.0.0.1:50649

[NotebookApp] Connecting to: tcp://127.0.0.1:35516

[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.close(pipeout)
    os.execlp("./test.sh", "abc")
    

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

parent()

$ cat test.sh

#!/bin/bash



script_name=$0

args=$@

current=`pwd`

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