diff --git a/moulinette/utils/process.py b/moulinette/utils/process.py index e4134498..e49d0d3d 100644 --- a/moulinette/utils/process.py +++ b/moulinette/utils/process.py @@ -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) - with subprocess.Popen(args, **kwargs) as p: + 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