This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author fsteffenhagen
Recipients fsteffenhagen
Date 2011-11-17.20:35:40
SpamBayes Score 6.362314e-06
Marked as misclassified No
Message-id <1321562143.65.0.570707046808.issue13422@psf.upfronthosting.co.za>
In-reply-to
Content
subprocess.Popen.communicate() hangs for daemonized subprocesses that leave a pipe open. The python caller, invoking the daemon subprocess, runs as long as the daemon process. This happens on POSIX platforms with python 2.7 as well as 3.2. 

Please find attached a simple python daemon, which leaves stderr pipe open. It runs for 10 sec and then exits.

To reproduce the problem run the following start script:
##################
# startpydaemon.py
import subprocess

cmd = 'python pydaemon.py'
print("Starting daemon that runs for 10 sec")
daemon = subprocess.Popen(cmd, 
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          shell=True)
stdout, stderr = daemon.communicate()
print("Stdout:")
print(stdout)
print("Stderr:")
print(stderr)
##################

Expected Behavior:
------------------
Daemon starter should exit immediately after the daemon process is initialized.

Actual Behavior:
----------------
Daemon starter waits for daemon process to be finished due to left open error pipe. 

Workaround:
-----------
One workaround is to not capture output from the left-open pipe. This way.
History
Date User Action Args
2011-11-17 20:35:44fsteffenhagensetrecipients: + fsteffenhagen
2011-11-17 20:35:43fsteffenhagensetmessageid: <1321562143.65.0.570707046808.issue13422@psf.upfronthosting.co.za>
2011-11-17 20:35:43fsteffenhagenlinkissue13422 messages
2011-11-17 20:35:42fsteffenhagencreate