mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[enh] Handle a particular 'stdinfo' output through named pipe
This commit is contained in:
parent
0665cb4dd5
commit
4f31cf0044
1 changed files with 24 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import errno
|
||||
import time
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
from moulinette.core import MoulinetteError
|
||||
|
||||
|
@ -59,9 +60,18 @@ def call_async_output(args, callback, **kwargs):
|
|||
raise ValueError('%s argument not allowed, '
|
||||
'it will be overridden.' % a)
|
||||
|
||||
|
||||
if "stdinfo" in kwargs and kwargs["stdinfo"] != None:
|
||||
assert len(callback) == 3
|
||||
stdinfo = kwargs.pop("stdinfo")
|
||||
os.mkfifo(stdinfo, 0600)
|
||||
else:
|
||||
kwargs.pop("stdinfo")
|
||||
stdinfo = None
|
||||
|
||||
# Validate callback argument
|
||||
if isinstance(callback, tuple):
|
||||
if len(callback) != 2:
|
||||
if len(callback) < 2:
|
||||
raise ValueError('callback argument should be a 2-tuple')
|
||||
kwargs['stdout'] = kwargs['stderr'] = subprocess.PIPE
|
||||
separate_stderr = True
|
||||
|
@ -80,6 +90,14 @@ def call_async_output(args, callback, **kwargs):
|
|||
stdout_reader, stdout_consum = async_file_reading(p.stdout, callback[0])
|
||||
if separate_stderr:
|
||||
stderr_reader, stderr_consum = async_file_reading(p.stderr, callback[1])
|
||||
if stdinfo:
|
||||
stdinfo_f = open(stdinfo, "r")
|
||||
stdinfo_reader, stdinfo_consum = async_file_reading(stdinfo_f, callback[2])
|
||||
while not stdinfo_reader.eof() and not stdinfo_reader.eof():
|
||||
time.sleep(.1)
|
||||
stdinfo_reader.join()
|
||||
stdinfo_consum.join()
|
||||
|
||||
while not stdout_reader.eof() and not stderr_reader.eof():
|
||||
time.sleep(.1)
|
||||
stderr_reader.join()
|
||||
|
@ -90,6 +108,11 @@ def call_async_output(args, callback, **kwargs):
|
|||
stdout_reader.join()
|
||||
stdout_consum.join()
|
||||
|
||||
if stdinfo:
|
||||
stdinfo_f.close()
|
||||
os.remove(stdinfo)
|
||||
os.rmdir(os.path.dirname(stdinfo))
|
||||
|
||||
# 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
|
||||
# bit to give hime the time to finish (while having a timeout)
|
||||
|
|
Loading…
Reference in a new issue