pep-550: Add a section about context isolation (#331)

This commit is contained in:
Yury Selivanov 2017-08-11 19:13:45 -04:00 committed by GitHub
parent 70d0a63390
commit 1e260e7a1e
1 changed files with 21 additions and 0 deletions

View File

@ -968,6 +968,27 @@ trampoline, making it impossible to intercept their ``yield`` points
outside of the Python interpreter. outside of the Python interpreter.
Is it possible to write a context manager to isolate EC changes?
----------------------------------------------------------------
Yes!
::
@contextlib.contextmanager
def isolated_context():
old_ctx = sys.get_execution_context()
try:
yield
finally:
sys.set_execution_context(old_ctx)
with isolated_context():
# Any Execution Context changes will not be visible
# outside of this block.
Reference Implementation Reference Implementation
======================== ========================