pep-0492: rename set_async_wrapper -> set_coroutine_wrapper

This commit is contained in:
Yury Selivanov 2015-04-17 17:14:47 -04:00
parent 118fa22b06
commit cd5e0b4fc5
1 changed files with 7 additions and 9 deletions

View File

@ -439,7 +439,7 @@ programs with asyncio's own functions instrumented. ``EventLoop.set_debug``, a
different debug facility, has no impact on ``@coroutine`` decorator's behavior.
With this proposal, coroutines is a native, distinct from generators,
concept. A new method ``set_async_wrapper`` is added to the ``sys`` module,
concept. A new method ``set_coroutine_wrapper`` is added to the ``sys`` module,
with which frameworks can provide advanced debugging facilities.
It is also important to make coroutines as fast and efficient as possible,
@ -453,18 +453,19 @@ Example::
def async_debug_wrap(generator):
return asyncio.AsyncDebugWrapper(generator)
sys.set_async_wrapper(async_debug_wrap)
sys.set_coroutine_wrapper(async_debug_wrap)
debug_me() # <- this line will likely GC the coroutine object and
# trigger AsyncDebugWrapper's code.
assert isinstance(debug_me(), AsyncDebugWrapper)
sys.set_async_wrapper(None) # <- this unsets any previously set wrapper
sys.set_coroutine_wrapper(None) # <- this unsets any
# previously set wrapper
assert not isinstance(debug_me(), AsyncDebugWrapper)
If ``sys.set_async_wrapper()`` is called twice, the new wrapper replaces the
previous wrapper. ``sys.set_async_wrapper(None)`` unsets the wrapper.
If ``sys.set_coroutine_wrapper()`` is called twice, the new wrapper replaces the
previous wrapper. ``sys.set_coroutine_wrapper(None)`` unsets the wrapper.
Glossary
@ -915,7 +916,7 @@ List of high-level changes and new protocols
5. New AST nodes: ``AsyncFor``, ``AsyncWith``, ``Await``; ``FunctionDef`` AST
node got a new argument ``is_async``.
6. New functions: ``sys.set_async_wrapper(callback)`` and
6. New functions: ``sys.set_coroutine_wrapper(callback)`` and
``types.async_def(gen)``.
7. New ``CO_ASYNC`` bit flag for code objects.
@ -936,12 +937,10 @@ All concepts proposed in this PEP are implemented [3]_ and can be tested.
import asyncio
async def echo_server():
print('Serving on localhost:8000')
await asyncio.start_server(handle_connection, 'localhost', 8000)
async def handle_connection(reader, writer):
print('New connection...')
@ -954,7 +953,6 @@ All concepts proposed in this PEP are implemented [3]_ and can be tested.
print('Sending {:.10}... back'.format(repr(data)))
writer.write(data)
loop = asyncio.get_event_loop()
loop.run_until_complete(echo_server())
try: