Skip to content

Commit

Permalink
Tolerate __builtins__ being a dict (rather than module) in is_timeout
Browse files Browse the repository at this point in the history
I'm still not sure how this happens, but somehow it does in
socket_test.test_error_is_timeout. As a result, is_timeout wouldn't get
a reference to TimeoutError, so the socket error would not be correctly
identified as a timeout.
  • Loading branch information
tipabu authored and temoto committed Oct 8, 2021
1 parent 2ea6991 commit bad82b6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions eventlet/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ def fun(*args, **kwargs):
return fun


if isinstance(__builtins__, dict): # seen when running tests on py310, but HOW??
_timeout_err = __builtins__.get('TimeoutError', Timeout)
else:
_timeout_err = getattr(__builtins__, 'TimeoutError', Timeout)


def is_timeout(obj):
py3err = getattr(__builtins__, 'TimeoutError', Timeout)
return bool(getattr(obj, 'is_timeout', False)) or isinstance(obj, py3err)
return bool(getattr(obj, 'is_timeout', False)) or isinstance(obj, _timeout_err)

0 comments on commit bad82b6

Please sign in to comment.