mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Cleaning / looks like it's working :/
This commit is contained in:
parent
8151ab3caf
commit
e3571eb93a
2 changed files with 17 additions and 19 deletions
|
@ -64,6 +64,9 @@ def call_async_output(args, callback, **kwargs):
|
||||||
assert len(callback) == 3
|
assert len(callback) == 3
|
||||||
stdinfo = kwargs.pop("stdinfo")
|
stdinfo = kwargs.pop("stdinfo")
|
||||||
os.mkfifo(stdinfo, 0600)
|
os.mkfifo(stdinfo, 0600)
|
||||||
|
# Open stdinfo for reading (in a nonblocking way, i.e. even
|
||||||
|
# if command does not write in the stdinfo pipe...)
|
||||||
|
stdinfo_f = os.open(stdinfo, os.O_RDONLY|os.O_NONBLOCK)
|
||||||
else:
|
else:
|
||||||
kwargs.pop("stdinfo")
|
kwargs.pop("stdinfo")
|
||||||
stdinfo = None
|
stdinfo = None
|
||||||
|
@ -90,17 +93,7 @@ def call_async_output(args, callback, **kwargs):
|
||||||
if separate_stderr:
|
if separate_stderr:
|
||||||
stderr_reader, stderr_consum = async_file_reading(p.stderr, callback[1])
|
stderr_reader, stderr_consum = async_file_reading(p.stderr, callback[1])
|
||||||
if stdinfo:
|
if stdinfo:
|
||||||
# Open stdinfo for reading (in a nonblocking way, i.e. even
|
|
||||||
# if command does not write in the stdinfo pipe...)
|
|
||||||
stdinfo_f = os.open(stdinfo, os.O_RDONLY|os.O_NONBLOCK)
|
|
||||||
stdinfo_reader, stdinfo_consum = async_file_reading(stdinfo_f, callback[2])
|
stdinfo_reader, stdinfo_consum = async_file_reading(stdinfo_f, callback[2])
|
||||||
while not stdout_reader.eof() or not stderr_reader.eof():
|
|
||||||
time.sleep(.1)
|
|
||||||
# Remove the stdinfo pipe
|
|
||||||
os.remove(stdinfo)
|
|
||||||
os.rmdir(os.path.dirname(stdinfo))
|
|
||||||
stdinfo_reader.join()
|
|
||||||
stdinfo_consum.join()
|
|
||||||
|
|
||||||
while not stdout_reader.eof() or not stderr_reader.eof():
|
while not stdout_reader.eof() or not stderr_reader.eof():
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
|
@ -112,6 +105,13 @@ def call_async_output(args, callback, **kwargs):
|
||||||
stdout_reader.join()
|
stdout_reader.join()
|
||||||
stdout_consum.join()
|
stdout_consum.join()
|
||||||
|
|
||||||
|
if stdinfo:
|
||||||
|
# Remove the stdinfo pipe
|
||||||
|
os.remove(stdinfo)
|
||||||
|
os.rmdir(os.path.dirname(stdinfo))
|
||||||
|
stdinfo_reader.join()
|
||||||
|
stdinfo_consum.join()
|
||||||
|
|
||||||
# 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
|
||||||
# bit to give hime the time to finish (while having a timeout)
|
# bit to give hime the time to finish (while having a timeout)
|
||||||
|
|
|
@ -41,15 +41,13 @@ class AsynchronousFileReader(Process):
|
||||||
else:
|
else:
|
||||||
data = ""
|
data = ""
|
||||||
while True:
|
while True:
|
||||||
# If nobody's writing in there anymore, get out
|
# Try to read (non-blockingly) a few bytes, append them to
|
||||||
if os.fstat(self._fd).st_nlink == 0:
|
# the buffer
|
||||||
print "Plop"
|
|
||||||
self._queue.put("(Info returning because no link)")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Read (non-blockingly) a few bytes, append them to the buffer
|
|
||||||
data += os.read(self._fd, 50)
|
data += os.read(self._fd, 50)
|
||||||
print data
|
|
||||||
|
# If nobody's writing in there anymore, get out
|
||||||
|
if not data and os.fstat(self._fd).st_nlink == 0:
|
||||||
|
return
|
||||||
|
|
||||||
# If we have data, extract a line (ending with \n) and feed
|
# If we have data, extract a line (ending with \n) and feed
|
||||||
# it to the consumer
|
# it to the consumer
|
||||||
|
@ -58,7 +56,7 @@ class AsynchronousFileReader(Process):
|
||||||
self._queue.put(lines[0])
|
self._queue.put(lines[0])
|
||||||
data = '\n'.join(lines[1:])
|
data = '\n'.join(lines[1:])
|
||||||
else:
|
else:
|
||||||
time.sleep(0.1)
|
time.sleep(0.05)
|
||||||
|
|
||||||
def eof(self):
|
def eof(self):
|
||||||
"""Check whether there is no more content to expect."""
|
"""Check whether there is no more content to expect."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue