Skip to content

Commit

Permalink
Merge pull request #27 from lukemartinlogan/master
Browse files Browse the repository at this point in the history
Fix unwreaped thread
  • Loading branch information
lukemartinlogan authored Oct 1, 2023
2 parents 2028e51 + ecc23fc commit 0256d92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions jarvis_util/shell/local_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, cmd, exec_info):
self.stderr = io.StringIO()
self.last_stdout_size = 0
self.last_stderr_size = 0
self.executing_ = True
self.print_stdout_thread = None
self.print_stderr_thread = None
self.exit_code = 0
Expand Down Expand Up @@ -99,7 +98,7 @@ def _start_bash_processes(self):
self.wait()

def wait(self):
self.proc.wait()
# self.proc.wait()
self.join_print_worker()
self.set_exit_code()
return self.exit_code
Expand All @@ -114,16 +113,20 @@ def get_pid(self):
return None

def print_stdout_worker(self):
while self.executing_:
while self.proc.poll() is None:
self.print_to_outputs(self.proc.stdout, self.stdout,
self.pipe_stdout_fp, sys.stdout)
time.sleep(25 / 1000)
self.print_to_outputs(self.proc.stdout, self.stdout,
self.pipe_stdout_fp, sys.stdout)

def print_stderr_worker(self):
while self.executing_:
while self.proc.poll() is None:
self.print_to_outputs(self.proc.stderr, self.stderr,
self.pipe_stderr_fp, sys.stderr)
time.sleep(25 / 1000)
self.print_to_outputs(self.proc.stderr, self.stderr,
self.pipe_stderr_fp, sys.stderr)

def print_to_outputs(self, proc_sysout, self_sysout, file_sysout, sysout):
# pylint: disable=W0702
Expand All @@ -138,13 +141,12 @@ def print_to_outputs(self, proc_sysout, self_sysout, file_sysout, sysout):
if file_sysout is not None:
file_sysout.write(line)
except:
pass
return
# pylint: enable=W0702

def join_print_worker(self):
if not self.executing_:
if isinstance(self.stdout, str):
return
self.executing_ = False
self.print_stdout_thread.join()
self.print_stderr_thread.join()
self.stdout = self.stdout.getvalue()
Expand Down
2 changes: 1 addition & 1 deletion jarvis_util/shell/pssh_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, cmd, exec_info):
self.execs_.append(SshExec(cmd, ssh_exec_info))
else:
self.execs_.append(
LocalExec(cmd, exec_info))
LocalExec(cmd, exec_info.mod(exec_async=True)))
if not self.exec_async:
self.wait()

Expand Down

0 comments on commit 0256d92

Please sign in to comment.