diff options
author | Bernát Gábor <bgabor8@bloomberg.net> | 2020-12-25 13:04:09 +0000 |
---|---|---|
committer | Bernát Gábor <bgabor8@bloomberg.net> | 2020-12-25 13:04:39 +0000 |
commit | 0bbdf445fc7d47d0dd31599872975534243ed555 (patch) | |
tree | 446c8de3a2155a3d4a14886376e36cb076a7d807 /src/tox/execute | |
parent | 631af1b0dd331c7a79c2d40ea4ef3bab1fd34632 (diff) | |
download | tox-git-0bbdf445fc7d47d0dd31599872975534243ed555.tar.gz |
Fix keyboard interrupt can fail
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
Diffstat (limited to 'src/tox/execute')
-rw-r--r-- | src/tox/execute/local_sub_process/read_via_thread_unix.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/tox/execute/local_sub_process/read_via_thread_unix.py b/src/tox/execute/local_sub_process/read_via_thread_unix.py index 03b5c9cf..ba156e7f 100644 --- a/src/tox/execute/local_sub_process/read_via_thread_unix.py +++ b/src/tox/execute/local_sub_process/read_via_thread_unix.py @@ -1,6 +1,7 @@ """ On UNIX we use select.select to ensure we drain in a non-blocking fashion. """ +import errno # pragma: win32 no cover import os # pragma: win32 no cover import select # pragma: win32 no cover from typing import Callable # pragma: win32 no cover @@ -18,14 +19,19 @@ class ReadViaThreadUnix(ReadViaThread): # pragma: win32 no cover while not self.stop.is_set(): # we need to drain the stream, but periodically give chance for the thread to break if the stop event has # been set (this is so that an interrupt can be handled) - ready, __, ___ = select.select([self.file_no], [], [], STOP_EVENT_CHECK_PERIODICITY_IN_MS) - if ready: - data = os.read(self.file_no, 1) - if data: - try: - self.handler(data) - except Exception: # noqa - pass + try: + ready, __, ___ = select.select([self.file_no], [], [], STOP_EVENT_CHECK_PERIODICITY_IN_MS) + if ready: + data = os.read(self.file_no, 1) + if data: + try: + self.handler(data) + except Exception: # noqa + pass + except OSError as exception: + if exception.errno == errno.EBADF: + break + raise def _drain_stream(self) -> bytes: result = bytearray() # on closed file read returns empty |