mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
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:
parent
b0063c4293
commit
ce3971093d
1 changed files with 9 additions and 2 deletions
|
@ -59,7 +59,7 @@ def call_async_output(args, callback, **kwargs):
|
||||||
Exit status of the command
|
Exit status of the command
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for a in ["stdout", "stderr"]:
|
for a in ["stdout", "stderr", "stdinfo"]:
|
||||||
if a in kwargs:
|
if a in kwargs:
|
||||||
raise ValueError("%s argument not allowed, " "it will be overridden." % a)
|
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"] = os.environ
|
||||||
kwargs["env"]["YNH_STDINFO"] = str(stdinfo.fdWrite)
|
kwargs["env"]["YNH_STDINFO"] = str(stdinfo.fdWrite)
|
||||||
|
|
||||||
|
try:
|
||||||
with subprocess.Popen(args, **kwargs) as p:
|
with subprocess.Popen(args, **kwargs) as p:
|
||||||
kwargs["stdout"].close()
|
kwargs["stdout"].close()
|
||||||
kwargs["stderr"].close()
|
kwargs["stderr"].close()
|
||||||
if stdinfo:
|
if stdinfo:
|
||||||
stdinfo.close()
|
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
|
# 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
|
# isn't finished just after having closed stdout and stderr, so we wait a
|
||||||
|
|
Loading…
Add table
Reference in a new issue