From 8dc3e438398046c6bb989e038cd08280aa356982 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Wed, 5 Oct 2016 19:32:49 -0400 Subject: Issue #28372: Fix asyncio to support formatting of non-python coroutines --- Lib/asyncio/coroutines.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Lib/asyncio/coroutines.py') diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py index 5cecc762df9..1db7030205d 100644 --- a/Lib/asyncio/coroutines.py +++ b/Lib/asyncio/coroutines.py @@ -261,6 +261,25 @@ def iscoroutine(obj): def _format_coroutine(coro): assert iscoroutine(coro) + if not hasattr(coro, 'cr_code') and not hasattr(coro, 'gi_code'): + # Most likely a Cython coroutine. + coro_name = getattr(coro, '__qualname__', coro.__name__) + coro_name = '{}()'.format(coro_name) + + running = False + try: + running = coro.cr_running + except AttributeError: + try: + running = coro.gi_running + except AttributeError: + pass + + if running: + return '{} running'.format(coro_name) + else: + return coro_name + coro_name = None if isinstance(coro, CoroWrapper): func = coro.func -- cgit v1.2.3