summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M. Larson <SethMichaelLarson@users.noreply.github.com>2017-03-23 16:45:16 -0500
committerGitHub <noreply@github.com>2017-03-23 16:45:16 -0500
commitb731bc453aaf70b952148652774a45ba812864ba (patch)
treed4c910fcc28b3cd02a2596600b4d3ef45456034e
parent84742495fd952f878fa6d0725d03d867ec39cd52 (diff)
downloadredis-py-b731bc453aaf70b952148652774a45ba812864ba.tar.gz
InterruptedError is not defined in Python 2
Fixes #845
-rw-r--r--redis/_compat.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/redis/_compat.py b/redis/_compat.py
index 4713d01..7d0e125 100644
--- a/redis/_compat.py
+++ b/redis/_compat.py
@@ -1,6 +1,11 @@
"""Internal module for Python 2 backwards compatibility."""
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,8 +20,12 @@ if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and
while True:
try:
return _select(rlist, wlist, xlist, timeout)
- except InterruptedError:
- continue
+ except InterruptedError as e:
+ # Python 2 does not define InterruptedError, instead
+ # try to catch an OSError with errno == EINTR == 4.
+ if hasattr(e, 'errno') and (e.errno == 4 or e.errno is None):
+ continue
+ raise e
# Wrapper for handling interruptable system calls.
def _retryable_call(s, func, *args, **kwargs):