Skip to content
Snippets Groups Projects
Commit dbe43435 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

resolve a #todo

parent 5afcd743
No related branches found
No related tags found
No related merge requests found
...@@ -10,8 +10,10 @@ logger = logging.getLogger(__name__) ...@@ -10,8 +10,10 @@ logger = logging.getLogger(__name__)
def read_nowait(process: subprocess.Popen, output_list: tp.List[str]): def read_nowait(process: subprocess.Popen, output_list: tp.List[str]):
try: try:
while process.stdout.readable(): while process.poll() is None:
line = process.stdout.readline() line = process.stdout.read(2048)
if line == '':
break
output_list.append(line) output_list.append(line)
except (IOError, OSError): except (IOError, OSError):
pass pass
...@@ -29,8 +31,6 @@ def call_and_return_stdout(args: tp.Union[str, tp.List[str]], ...@@ -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 A bytes object will be returned if encoding is not defined, else stdout will be decoded
according to specified encoding. 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 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 :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 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]], ...@@ -54,6 +54,7 @@ def call_and_return_stdout(args: tp.Union[str, tp.List[str]],
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
proc.kill() proc.kill()
proc.wait() proc.wait()
reader_thread.join()
if proc.returncode != expected_return_code: if proc.returncode != expected_return_code:
raise ProcessFailed(proc.returncode) raise ProcessFailed(proc.returncode)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment