subprocess + python-daemon - bug/problem?

Discussion in 'Python' started by Andy Clegg, Jul 9, 2009.

  1. Andy  Clegg

    Andy Clegg Guest

    Hi all,

    I'm trying to daemonize a python program, and occasionally have it run
    subprocesses, however I'm running into a nasty error, as follows:

    "File "/users/rsg/ancl/devcocast/devcocast-svn/scripts/DaemonSpawnTes
    t.py", line 5, in <module>
    subprocess.Popen('echo 1').wait()
    File "/usr/lib64/python2.5/subprocess.py", line 594, in __init__
    errread, errwrite)
    File "/usr/lib64/python2.5/subprocess.py", line 1089, in _execute_ch
    ild
    os.waitpid(self.pid, 0)
    OSError: [Errno 10] No child processes"

    The minimal testcase showing this problem is as follows:

    "import daemon
    import subprocess

    daemon.DaemonContext(stderr = open("fakeConsole.txt","w+")).open()
    subprocess.Popen('echo 1').wait()"

    So there is no threading going on (I've found some bugs relating to
    subprocess and threading). I'm using Fedora 10, Python 2.5.2, and
    python-daemon 1.4.6 from here http://pypi.python.org/pypi/python-daemon/
    ..

    If anyone can shed some light on the situation, I'd be extremely
    grateful!

    Yours,

    Andy
     
    Andy Clegg, Jul 9, 2009
    #1
    1. Advertising

  2. Andy  Clegg

    Andy Clegg Guest

    My apologies, the python code should have been:

    "import daemon
    import subprocess

    daemon.DaemonContext(stderr = open("fakeConsole.txt","w+")).open()
    subprocess.Popen(['echo','1']).wait()"

    However the error remains the same.

    Yours,

    Andy

    On Jul 9, 10:26 am, Andy Clegg <> wrote:
    > Hi all,
    >
    > I'm trying to daemonize a python program, and occasionally have it run
    > subprocesses, however I'm running into a nasty error, as follows:
    >
    > "File "/users/rsg/ancl/devcocast/devcocast-svn/scripts/DaemonSpawnTes
    > t.py", line 5, in <module>
    >     subprocess.Popen('echo 1').wait()
    >   File "/usr/lib64/python2.5/subprocess.py", line 594, in __init__
    >     errread, errwrite)
    >   File "/usr/lib64/python2.5/subprocess.py", line 1089, in _execute_ch
    > ild
    >     os.waitpid(self.pid, 0)
    > OSError: [Errno 10] No child processes"
    >
    > The minimal testcase showing this problem is as follows:
    >
    > "import daemon
    > import subprocess
    >
    > daemon.DaemonContext(stderr = open("fakeConsole.txt","w+")).open()
    > subprocess.Popen('echo 1').wait()"
    >
    > So there is no threading going on (I've found some bugs relating to
    > subprocess and threading). I'm using Fedora 10, Python 2.5.2, and
    > python-daemon 1.4.6 from herehttp://pypi.python.org/pypi/python-daemon/
    > .
    >
    > If anyone can shed some light on the situation, I'd be extremely
    > grateful!
    >
    > Yours,
    >
    > Andy
     
    Andy Clegg, Jul 9, 2009
    #2
    1. Advertising

  3. Andy  Clegg

    Sewar Guest

    I got the same bug.

    Traceback (most recent call last):
    File "./script1.py", line 30, in <module>
    call(["python", "script2.py", "arg1"], stdout=sys.stdout, stderr=STDOUT)
    File "/usr/lib/python2.6/subprocess.py", line 444, in call
    return Popen(*popenargs, **kwargs).wait()
    File "/usr/lib/python2.6/subprocess.py", line 1123, in wait
    pid, sts = os.waitpid(self.pid, 0)
    OSError: [Errno 10] No child processes
     
    Sewar, Sep 6, 2009
    #3
  4. Andy  Clegg

    Sewar Guest

    I looked at other daemon libraries and snippets, it's clearly the bug is in
    subprocess not python-daemon.
    Then I found Python bug #1731717 which discusses it.

    I wish my project was opensource so I can post more specific test cases.

    #1731717 http://bugs.python.org/issue1731717

    Thanks
     
    Sewar, Sep 8, 2009
    #4
  5. Andy  Clegg

    Joel Martin Guest

    On Sep 8, 5:19 pm, Ben Finney <> wrote:
    > Sewar <> writes:
    > > I looked at other daemon libraries and snippets, it's clearly the bug is in
    > > subprocess not python-daemon.
    > > Then I found Python bug #1731717 which discusses it.


    I'm running python-2.6.2 which supposedly has the fix for #1731717.
    However I still still the problem with subprocess after daemonizing.
    I've narrowed it down to just the setting of the SIGCLD signal.

    You can reproduce the problem thus (in 2.4.6, 2.5.4 and 2.6.2):

    import subprocess, signal
    signal.signal(signal.SIGCLD, signal.SIG_IGN)
    subprocess.Popen(['echo','foo']).wait()


    This patch allows python-daemon to work with subprocess:

    --- daemon.py (revision 146)
    +++ daemon.py (working copy)
    @@ -140,8 +140,6 @@
    actually defined in the ``signal`` module will appear in
    the
    default map:

    - * ``signal.SIGCLD``: ``None``
    -
    * ``signal.SIGTTIN``: ``None``

    * ``signal.SIGTTOU``: ``None``
    @@ -730,7 +728,6 @@

    """
    name_map = {
    - 'SIGCLD': None,
    'SIGTSTP': None,
    'SIGTTIN': None,
    'SIGTTOU': None,
     
    Joel Martin, Sep 16, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean-Paul Calderone
    Replies:
    0
    Views:
    467
    Jean-Paul Calderone
    Mar 20, 2009
  2. Floris Bruynooghe
    Replies:
    1
    Views:
    462
    Floris Bruynooghe
    Mar 24, 2009
  3. Thomas Courbon

    Python daemonisation with python-daemon

    Thomas Courbon, Apr 30, 2010, in forum: Python
    Replies:
    0
    Views:
    1,609
    Thomas Courbon
    Apr 30, 2010
  4. hiral
    Replies:
    2
    Views:
    614
    Jean-Michel Pichavant
    May 5, 2010
  5. Daemon Win32::Daemon;

    , Sep 7, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    264
Loading...

Share This Page