summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Shepelev <temotor@gmail.com>2017-07-02 12:12:55 +0300
committerSergey Shepelev <temotor@gmail.com>2020-10-19 03:26:20 +0300
commit18c889e99360ddf76cdcad42090fd87e481e84fb (patch)
tree3f8f50119b3be129995a8e8a746ecbe90eef7c93
parentf2ebbb87590d0fa4f173599806dfec88caeb9fb9 (diff)
downloadeventlet-subprocess-413-more.tar.gz
green.subprocess: keep SubprocessError identitysubprocess-413-more
https://github.com/eventlet/eventlet/issues/413
-rw-r--r--eventlet/green/subprocess.py12
-rw-r--r--tests/isolated/subprocess_exception_identity.py1
2 files changed, 10 insertions, 3 deletions
diff --git a/eventlet/green/subprocess.py b/eventlet/green/subprocess.py
index f021ced..892aaaf 100644
--- a/eventlet/green/subprocess.py
+++ b/eventlet/green/subprocess.py
@@ -20,9 +20,10 @@ patcher.inject('subprocess', globals(), *to_patch)
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):
@@ -139,5 +140,10 @@ del patched_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
diff --git a/tests/isolated/subprocess_exception_identity.py b/tests/isolated/subprocess_exception_identity.py
index 24fdadd..abc648b 100644
--- a/tests/isolated/subprocess_exception_identity.py
+++ b/tests/isolated/subprocess_exception_identity.py
@@ -6,6 +6,7 @@ if __name__ == '__main__':
cases = (
'CalledProcessError',
+ 'SubprocessError',
'TimeoutExpired',
)
for c in cases: