Subprocess troubles from a daemon
Eiríkur Hjartarson
Eirikur.Hjartarson at decode.is
Fri Apr 13 07:04:25 EDT 2012
Hi,
I think I have possibly found a bug in the subprocess module. The (potential) bug appears when executing a subprocess from a daemon (after double-forking). This is on RHEL 6.2 with python version 2.6.6.
The problem can be demonstrated with the two attached files, both files should be made executable and then run './example'. There is output both on stdout and in the file: '/tmp/example.log'.
The 'service' program writes on both stdout and stderr, sleeps 10 seconds and exits.
The 'exemple' program executes the subprocess, 'service', (to demonstrate that the subprocess module works), then double-forks, closes file-desciptors, points sys.stdout and sys.stderr to a logfile and executes the 'service' subprocess again. The second execution fails when the subprocess references sys.stderr. If the ' print >>sys.stderr, ...' line is commented out of the 'service' file, the second execution succeeds. The first call to subprocess.Popen produces output on stdout, the second call outputs to '/tmp/example.log'. On the other hand, if the lines in 'service' that are commented out (write on '/tmp/service.out') are enabled, the stderr output appears in that file.
If I use 'os.popen3' instead of ' subprocess.Popen', the problem disappears.
I would love to hear your opinions on this :-)
Regards,
--
Eiríkur Hjartarson
deCODE genetics
Sturlugötu 7
IS-101 Reykjavík
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example
Type: application/octet-stream
Size: 2511 bytes
Desc: example
URL: <http://mail.python.org/pipermail/python-list/attachments/20120413/0e92175e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: service
Type: application/octet-stream
Size: 358 bytes
Desc: service
URL: <http://mail.python.org/pipermail/python-list/attachments/20120413/0e92175e/attachment-0001.obj>
More information about the Python-list
mailing list