[Python-checkins] peps: pep-0492: We always raise RuntimeWarning for non-awaited coroutines

yury.selivanov python-checkins at python.org
Tue May 5 05:27:20 CEST 2015


https://hg.python.org/peps/rev/ae24829f1bf8
changeset:   5822:ae24829f1bf8
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Mon May 04 23:27:16 2015 -0400
summary:
  pep-0492: We always raise RuntimeWarning for non-awaited coroutines

files:
  pep-0492.txt |  37 +++++++++++--------------------------
  1 files changed, 11 insertions(+), 26 deletions(-)


diff --git a/pep-0492.txt b/pep-0492.txt
--- a/pep-0492.txt
+++ b/pep-0492.txt
@@ -91,7 +91,7 @@
     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 @@
   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 @@
 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

-- 
Repository URL: https://hg.python.org/peps


More information about the Python-checkins mailing list