Skip to content

Commit 302731f

Browse files
authored
Merge pull request #846 from SethMichaelLarson/patch-1
InterruptedError is not defined in Python 2
2 parents 8474249 + 99e9293 commit 302731f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

redis/_compat.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
"""Internal module for Python 2 backwards compatibility."""
2+
import errno
23
import sys
34

5+
try:
6+
InterruptedError = InterruptedError
7+
except:
8+
InterruptedError = OSError
9+
410
# For Python older than 3.5, retry EINTR.
511
if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and
612
sys.version_info[1] < 5):
@@ -15,8 +21,12 @@ def select(rlist, wlist, xlist, timeout):
1521
while True:
1622
try:
1723
return _select(rlist, wlist, xlist, timeout)
18-
except InterruptedError:
19-
continue
24+
except InterruptedError as e:
25+
# Python 2 does not define InterruptedError, instead
26+
# try to catch an OSError with errno == EINTR == 4.
27+
if getattr(e, 'errno', None) == getattr(errno, 'EINTR', 4):
28+
continue
29+
raise
2030

2131
# Wrapper for handling interruptable system calls.
2232
def _retryable_call(s, func, *args, **kwargs):

0 commit comments

Comments
 (0)