From 7c481b6e7969d7d81ee773418b2fd71aad587397 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 4 May 2015 23:27:16 -0400 Subject: [PATCH] pep-0492: We always raise RuntimeWarning for non-awaited coroutines --- pep-0492.txt | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/pep-0492.txt b/pep-0492.txt index aace0fdb7..791d31795 100644 --- a/pep-0492.txt +++ b/pep-0492.txt @@ -91,7 +91,7 @@ The following new syntax is used to declare a *native coroutine*:: async def read_data(db): pass -Key properties of *native coroutines*: +Key properties of *coroutines*: * ``async def`` functions are always coroutines, even if they do not contain ``await`` expressions. @@ -117,6 +117,9 @@ Key properties of *native coroutines*: and are replaced with a ``RuntimeError``. For regular generators such behavior requires a future import (see PEP 479). +* When a *coroutine* is garbage collected, a ``RuntimeWarning`` is + raised if it was never awaited on (see also `Debugging Features`_.) + * See also `Coroutine objects`_ section. @@ -648,31 +651,13 @@ 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. New methods ``set_coroutine_wrapper`` and -``get_coroutine_wrapper`` are 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, therefore there are no debug features enabled by default. - -Example:: - - async def debug_me(): - await asyncio.sleep(1) - - def async_debug_wrap(generator): - return asyncio.CoroWrapper(generator) - - sys.set_coroutine_wrapper(async_debug_wrap) - - debug_me() # <- this line will likely GC the coroutine object and - # trigger asyncio.CoroWrapper's code. - - assert isinstance(debug_me(), asyncio.CoroWrapper) - - sys.set_coroutine_wrapper(None) # <- this unsets any - # previously set wrapper - assert not isinstance(debug_me(), asyncio.CoroWrapper) +concept. *In addition* to a ``RuntimeWarning`` being raised on +coroutines that were never awaited, it is proposed to add two new +functions to the ``sys`` module: ``set_coroutine_wrapper`` and +``get_coroutine_wrapper``. This is to enable advanced debugging +facilities in asyncio and other frameworks (such as displaying where +exactly coroutine was created, and a more detailed stack trace of where +it was garbage collected). New Standard Library Functions