未验证 提交 26091021 编写于 作者: A Amador Pahim

Merge branch 'clebergnu-fddrainer_combined_flush'

Signed-off-by: NAmador Pahim <apahim@redhat.com>
...@@ -376,8 +376,19 @@ class FDDrainer(object): ...@@ -376,8 +376,19 @@ class FDDrainer(object):
self._thread.daemon = True self._thread.daemon = True
self._thread.start() self._thread.start()
def join(self): def flush(self):
self._thread.join() self._thread.join()
if self._stream_logger is not None:
for handler in self._stream_logger.handlers:
# FileHandler has a close() method, which we expect will
# flush the file on disk. SocketHandler, MemoryHandler
# and other logging handlers (custom ones?) also have
# the same interface, so let's try to use it if available
stream = getattr(handler, 'stream', None)
if stream is not None:
os.fsync(stream.fileno())
if hasattr(handler, 'close'):
handler.close()
class SubProcess(object): class SubProcess(object):
...@@ -580,10 +591,12 @@ class SubProcess(object): ...@@ -580,10 +591,12 @@ class SubProcess(object):
Close subprocess stdout and stderr, and put values into result obj. Close subprocess stdout and stderr, and put values into result obj.
""" """
# Cleaning up threads # Cleaning up threads
if self._combined_drainer is not None:
self._combined_drainer.flush()
if self._stdout_drainer is not None: if self._stdout_drainer is not None:
self._stdout_drainer.join() self._stdout_drainer.flush()
if self._stderr_drainer is not None: if self._stderr_drainer is not None:
self._stderr_drainer.join() self._stderr_drainer.flush()
# Clean subprocess pipes and populate stdout/err # Clean subprocess pipes and populate stdout/err
self.result.stdout = self.get_stdout() self.result.stdout = self.get_stdout()
self.result.stderr = self.get_stderr() self.result.stderr = self.get_stderr()
......
...@@ -242,7 +242,7 @@ class FDDrainerTests(unittest.TestCase): ...@@ -242,7 +242,7 @@ class FDDrainerTests(unittest.TestCase):
os.write(write_fd, content) os.write(write_fd, content)
os.write(write_fd, "finish") os.write(write_fd, "finish")
os.close(write_fd) os.close(write_fd)
fd_drainer.join() fd_drainer.flush()
self.assertEqual(fd_drainer.data.getvalue(), self.assertEqual(fd_drainer.data.getvalue(),
"foobarbazfoo\nbar\nbaz\n\nfinish") "foobarbazfoo\nbar\nbaz\n\nfinish")
...@@ -270,7 +270,7 @@ class FDDrainerTests(unittest.TestCase): ...@@ -270,7 +270,7 @@ class FDDrainerTests(unittest.TestCase):
fd_drainer.start() fd_drainer.start()
os.write(write_fd, "should go to the log\n") os.write(write_fd, "should go to the log\n")
os.close(write_fd) os.close(write_fd)
fd_drainer.join() fd_drainer.flush()
self.assertEqual(fd_drainer.data.getvalue(), self.assertEqual(fd_drainer.data.getvalue(),
"should go to the log\n") "should go to the log\n")
self.assertTrue(handler.caught_record) self.assertTrue(handler.caught_record)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册