Skip to content

Commit a96939b

Browse files
committed
Renamed stuff and removed unneeded KeyboardInterrupt protection
1 parent bbea550 commit a96939b

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

cmd2/cmd2.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,9 +1924,9 @@ def _redirect_output(self, statement: Statement) -> Tuple[bool, RedirectionSaved
19241924
# Create a pipe with read and write sides
19251925
read_fd, write_fd = os.pipe()
19261926

1927-
# Open each side of the pipe and set stdout accordingly
1928-
pipe_read = io.open(read_fd, 'r')
1929-
pipe_write = io.open(write_fd, 'w')
1927+
# Open each side of the pipe
1928+
subproc_stdin = io.open(read_fd, 'r')
1929+
new_stdout = io.open(write_fd, 'w')
19301930

19311931
# We want Popen to raise an exception if it fails to open the process. Thus we don't set shell to True.
19321932
try:
@@ -1943,19 +1943,19 @@ def _redirect_output(self, statement: Statement) -> Tuple[bool, RedirectionSaved
19431943
# For any stream that is a StdSim, we will use a pipe so we can capture its output
19441944
proc = \
19451945
subprocess.Popen(statement.pipe_to,
1946-
stdin=pipe_read,
1946+
stdin=subproc_stdin,
19471947
stdout=subprocess.PIPE if isinstance(self.stdout, utils.StdSim) else self.stdout,
19481948
stderr=subprocess.PIPE if isinstance(sys.stderr, utils.StdSim) else sys.stderr,
19491949
creationflags=creationflags,
19501950
start_new_session=start_new_session)
19511951

19521952
saved_state.redirecting = True
19531953
saved_state.pipe_proc_reader = utils.ProcReader(proc, self.stdout, sys.stderr)
1954-
sys.stdout = self.stdout = pipe_write
1954+
sys.stdout = self.stdout = new_stdout
19551955
except Exception as ex:
19561956
self.perror('Failed to open pipe because - {}'.format(ex), traceback_war=False)
1957-
pipe_read.close()
1958-
pipe_write.close()
1957+
subproc_stdin.close()
1958+
new_stdout.close()
19591959
redir_error = True
19601960

19611961
elif statement.output:

cmd2/utils.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -414,19 +414,14 @@ def terminate(self) -> None:
414414

415415
def wait(self) -> None:
416416
"""Wait for the process to finish"""
417-
while True:
418-
try:
419-
if self._out_thread.is_alive():
420-
self._out_thread.join()
421-
if self._err_thread.is_alive():
422-
self._err_thread.join()
423-
424-
# Handle case where the process ended before the last read could be done.
425-
# This will return None for the streams that weren't pipes.
426-
out, err = self._proc.communicate()
427-
break
428-
except KeyboardInterrupt:
429-
pass
417+
if self._out_thread.is_alive():
418+
self._out_thread.join()
419+
if self._err_thread.is_alive():
420+
self._err_thread.join()
421+
422+
# Handle case where the process ended before the last read could be done.
423+
# This will return None for the streams that weren't pipes.
424+
out, err = self._proc.communicate()
430425

431426
if out:
432427
self._write_bytes(self._stdout, out)

0 commit comments

Comments
 (0)