From dbe434354d8febebb2812106872105b2eebeb1ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Wed, 29 Apr 2020 16:54:49 +0200
Subject: [PATCH] resolve a #todo

---
 satella/processes.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/satella/processes.py b/satella/processes.py
index 7a0b9a78..eea97a3a 100644
--- a/satella/processes.py
+++ b/satella/processes.py
@@ -10,8 +10,10 @@ logger = logging.getLogger(__name__)
 
 def read_nowait(process: subprocess.Popen, output_list: tp.List[str]):
     try:
-        while process.stdout.readable():
-            line = process.stdout.readline()
+        while process.poll() is None:
+            line = process.stdout.read(2048)
+            if line == '':
+                break
             output_list.append(line)
     except (IOError, OSError):
         pass
@@ -29,8 +31,6 @@ def call_and_return_stdout(args: tp.Union[str, tp.List[str]],
     A bytes object will be returned if encoding is not defined, else stdout will be decoded
     according to specified encoding.
 
-    #todo every usage of this call will spawn a daemonic thread, pending a fix
-
     :param args: arguments to run the program with. If passed a string, it will be split on space.
     :param timeout: amount of seconds to wait for the process result. If process does not complete
         within this time, it will be sent a SIGKILL
@@ -54,6 +54,7 @@ def call_and_return_stdout(args: tp.Union[str, tp.List[str]],
     except subprocess.TimeoutExpired:
         proc.kill()
         proc.wait()
+    reader_thread.join()
 
     if proc.returncode != expected_return_code:
         raise ProcessFailed(proc.returncode)
-- 
GitLab