Message233797
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. |
|
Date |
User |
Action |
Args |
2015-01-10 03:05:50 | martin.panter | set | recipients:
+ martin.panter, whissi |
2015-01-10 03:05:50 | martin.panter | set | messageid: <1420859150.55.0.202133243814.issue23213@psf.upfronthosting.co.za> |
2015-01-10 03:05:50 | martin.panter | link | issue23213 messages |
2015-01-10 03:05:49 | martin.panter | create | |
|