call_async_output: we can't use stdinfo in kwargs, close stdout, stderr and stdinfo if subprocess.Popen raise an exception

This commit is contained in:
Kay0u 2021-01-25 18:53:33 +01:00
parent b0063c4293
commit ce3971093d
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D

View file

@ -59,7 +59,7 @@ def call_async_output(args, callback, **kwargs):
Exit status of the command
"""
for a in ["stdout", "stderr"]:
for a in ["stdout", "stderr", "stdinfo"]:
if a in kwargs:
raise ValueError("%s argument not allowed, " "it will be overridden." % a)
@ -72,11 +72,18 @@ def call_async_output(args, callback, **kwargs):
kwargs["env"] = os.environ
kwargs["env"]["YNH_STDINFO"] = str(stdinfo.fdWrite)
try:
with subprocess.Popen(args, **kwargs) as p:
kwargs["stdout"].close()
kwargs["stderr"].close()
if stdinfo:
stdinfo.close()
except TypeError:
kwargs["stdout"].close()
kwargs["stderr"].close()
if stdinfo:
stdinfo.close()
raise
# on slow hardware, in very edgy situations it is possible that the process
# isn't finished just after having closed stdout and stderr, so we wait a