pep-550: Fix PEP 521 example. (#337)

This commit is contained in:
Yury Selivanov 2017-08-12 01:36:43 -04:00 committed by GitHub
parent fd0f25e2dc
commit e8a06c9a79
1 changed files with 10 additions and 8 deletions

View File

@ -942,30 +942,32 @@ The following code::
would become this::
local = threading.local()
class Context:
def __enter__(self):
self.old_x = get_execution_context_item('x')
set_execution_context_item('x', 'something')
self.old_x = getattr(local, 'x', None)
local.x = 'something'
def __suspend__(self):
set_execution_context_item('x', self.old_x)
local.x = self.old_x
def __resume__(self):
set_execution_context_item('x', 'something')
local.x = 'something'
def __exit__(self, *err):
set_execution_context_item('x', self.old_x)
local.x = self.old_x
Besides complicating the protocol, the implementation will likely
negatively impact performance of coroutines, generators, and any code
that uses context managers, and will notably complicate the
interpreter implementation. It also does not solve the leaking state
problem for greenlet/gevent.
interpreter implementation.
:pep:`521` also does not provide any mechanism to propagate state
in a local context, like storing a request object in an HTTP request
handler to have better logging.
handler to have better logging. Nor does it solve the leaking state
problem for greenlet/gevent.
Can Execution Context be implemented outside of CPython?