subprocess + python-daemon - bug/problem?

A

Andy Clegg

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
 
A

Andy Clegg

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
 
S

Sewar

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
 
S

Sewar

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
 
J

Joel Martin

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top