Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#52: Do not exit immediately, wait for the thread
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Oct 23, 2020
1 parent 6ee41bb commit 298a5a6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/rkd/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def check_call(command: str, script: Optional[str] = ''):
os.environ['PYTHONUNBUFFERED'] = "1"

old_tty = termios.tcgetattr(sys.stdin)
fd_thread = None

try:
tty.setraw(sys.stdin.fileno())

Expand All @@ -56,12 +58,15 @@ def check_call(command: str, script: Optional[str] = ''):
bufsize=64, close_fds=ON_POSIX, universal_newlines=False, preexec_fn=os.setsid)

out_buffer = TextBuffer(buffer_size=1024 * 10)
stdout_thread = Thread(target=push_output, args=(process, primary_fd, out_buffer))
stdout_thread.daemon = True
stdout_thread.start()
fd_thread = Thread(target=push_output, args=(process, primary_fd, out_buffer))
fd_thread.daemon = True
fd_thread.start()

exit_code = process.wait()
finally:
if fd_thread:
fd_thread.join()

termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty)

if exit_code > 0:
Expand Down

0 comments on commit 298a5a6

Please sign in to comment.