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 martin.panter
Recipients martin.panter, whissi
Date 2015-01-10.03:05:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1420859150.55.0.202133243814.issue23213@psf.upfronthosting.co.za>
In-reply-to
Content
I suspect this is not a bug but a misunderstanding of how communiate(), pipes, daemon processes, etc, work. If communicate() didn’t wait for stderr to be closed, then how would it know it had read all the data that was written into the pipe?

I don’t have that version of “systemd”, but I guess your daemon leaves its output pipes open and continues to run in the background, so communicate() is waiting in case the daemon writes anything to the pipes. This would demonstrate the same situation using a Python subprocess:

import subprocess
import sys
script = """import os, time
if not os.fork():  # Child process
    time.sleep(30)
    print("Finally!")
"""
args = (sys.executable, "-c", script)
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc.communicate()
# Hangs for 30 s and then returns (b'Finally!\n', b'')

If you want communicate() to return as soon as a daemon forks into the background, don’t read from the daemon’s output pipes. If you want to read data that the foreground process writes and ignore any data that the background process might write to the same pipes, that’s asking for race conditions.
History
Date User Action Args
2015-01-10 03:05:50martin.pantersetrecipients: + martin.panter, whissi
2015-01-10 03:05:50martin.pantersetmessageid: <1420859150.55.0.202133243814.issue23213@psf.upfronthosting.co.za>
2015-01-10 03:05:50martin.panterlinkissue23213 messages
2015-01-10 03:05:49martin.pantercreate