Skip to content

Commit

Permalink
green.subprocess: keep SubprocessError identity
Browse files Browse the repository at this point in the history
  • Loading branch information
temoto committed Oct 19, 2020
1 parent f2ebbb8 commit 18c889e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions eventlet/green/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
subprocess_orig = patcher.original("subprocess")
subprocess_imported = sys.modules.get('subprocess', subprocess_orig)
mswindows = sys.platform == "win32"
_MISSING = object()


if getattr(subprocess_orig, 'TimeoutExpired', None) is None:
if getattr(subprocess_orig, 'TimeoutExpired', _MISSING) is _MISSING:
# Backported from Python 3.3.
# https://bitbucket.org/eventlet/eventlet/issue/89
class TimeoutExpired(Exception):
Expand Down Expand Up @@ -139,5 +140,10 @@ def patched_function(function):

# Keep exceptions identity.
# https://github.com/eventlet/eventlet/issues/413
CalledProcessError = subprocess_imported.CalledProcessError
del subprocess_imported
_current_module = sys.modules[__name__]
_keep_names = ('CalledProcessError', 'SubprocessError')
for k in _keep_names:
v = getattr(subprocess_imported, k, _MISSING)
if v is not _MISSING:
setattr(_current_module, k, v)
del _current_module, _keep_names, k, v, subprocess_imported
1 change: 1 addition & 0 deletions tests/isolated/subprocess_exception_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

cases = (
'CalledProcessError',
'SubprocessError',
'TimeoutExpired',
)
for c in cases:
Expand Down

0 comments on commit 18c889e

Please sign in to comment.