Martin Panter added the comment:
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.
----------
nosy: +vadmium
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue23213>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com