Skip to content

Commit

Permalink
Merge pull request #846 from SethMichaelLarson/patch-1
Browse files Browse the repository at this point in the history
InterruptedError is not defined in Python 2
  • Loading branch information
andymccurdy committed Mar 23, 2017
2 parents 8474249 + 99e9293 commit 302731f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions redis/_compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""Internal module for Python 2 backwards compatibility."""
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):
Expand All @@ -15,8 +21,12 @@ def select(rlist, wlist, xlist, timeout):
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 getattr(e, 'errno', None) == getattr(errno, 'EINTR', 4):
continue
raise

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

0 comments on commit 302731f

Please sign in to comment.