mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[fix] Update call_async_output to make use of start_async_file_reading
This commit is contained in:
parent
8477c73069
commit
98f80e30ba
1 changed files with 8 additions and 13 deletions
|
@ -1,10 +1,11 @@
|
||||||
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
try:
|
try:
|
||||||
from pipes import quote # Python2 & Python3 <= 3.2
|
from pipes import quote # Python2 & Python3 <= 3.2
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from shlex import quote # Python3 >= 3.3
|
from shlex import quote # Python3 >= 3.3
|
||||||
|
|
||||||
from .stream import NonBlockingStreamReader
|
from .stream import start_async_file_reading
|
||||||
|
|
||||||
# Prevent to import subprocess only for common classes
|
# Prevent to import subprocess only for common classes
|
||||||
CalledProcessError = subprocess.CalledProcessError
|
CalledProcessError = subprocess.CalledProcessError
|
||||||
|
@ -55,22 +56,16 @@ def call_async_output(args, callback, **kwargs):
|
||||||
stderr=subprocess.STDOUT, **kwargs)
|
stderr=subprocess.STDOUT, **kwargs)
|
||||||
|
|
||||||
# Wrap and get command output
|
# Wrap and get command output
|
||||||
stream = NonBlockingStreamReader(p.stdout)
|
reader, queue = start_async_file_reading(p.stdout)
|
||||||
while True:
|
while not reader.eof():
|
||||||
line = stream.readline(True, 0.1)
|
while not queue.empty():
|
||||||
if not line:
|
line = queue.get()
|
||||||
# Check if process has terminated
|
|
||||||
returncode = p.poll()
|
|
||||||
if returncode is not None:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
callback(line.rstrip())
|
callback(line.rstrip())
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
stream.close()
|
reader.join()
|
||||||
|
return p.poll()
|
||||||
return returncode
|
|
||||||
|
|
||||||
|
|
||||||
# Call multiple commands -----------------------------------------------
|
# Call multiple commands -----------------------------------------------
|
||||||
|
|
Loading…
Add table
Reference in a new issue