InterruptedError does not exist in Python < 3.3.
Remove InterruptedError in favor of using select.error. Support for the
2.7 series requires this because InterruptedError was not introduced
until Python 3.3.
import errno
import sys
-try:
- InterruptedError = InterruptedError
-except:
- InterruptedError = OSError
-
# For Python older than 3.5, retry EINTR.
if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and
sys.version_info[1] < 5):
@@ -15,16 +10,14 @@ if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and
import time
import errno
- from select import select as _select
+ from select import select as _select, error as select_error
def select(rlist, wlist, xlist, timeout):
while True:
try:
return _select(rlist, wlist, xlist, timeout)
- except InterruptedError as e:
- # Python 2 does not define InterruptedError, instead
- # try to catch an OSError with errno == EINTR == 4.
- if getattr(e, 'errno', None) == getattr(errno, 'EINTR', 4):
+ except select_error as e:
+ if e.args[0] == errno.EINTR:
continue
raise
