import asyncio

from asyncio import coroutines


def _format_coroutine(coro):
    if asyncio.iscoroutine(coro) and not hasattr(coro, 'cr_code'):
        # Most likely a Cython coroutine
        coro_name = '{}()'.format(coro.__qualname__ or coro.__name__)
        if coro.cr_running:
            return '{} running'.format(coro_name)
        else:
            return coro_name

    return _old_format_coroutine(coro)


_old_format_coroutine = coroutines._format_coroutine
coroutines._format_coroutine = _format_coroutine

import asyncio

from asyncio import coroutines


def _format_coroutine(coro):
    if asyncio.iscoroutine(coro) \
            and not hasattr(coro, 'cr_code') \
            and not hasattr(coro, 'gi_code'):

        # Most likely a Cython coroutine
        coro_name = '{}()'.format(coro.__qualname__ or 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

    return _old_format_coroutine(coro)


_old_format_coroutine = coroutines._format_coroutine
coroutines._format_coroutine = _format_coroutine

Fix patched _format_coroutine to support Cython generators
Fix patched _format_coroutine to support Cython generators

  import asyncio
  
  from asyncio import coroutines
  
  
  def _format_coroutine(coro):
-     if asyncio.iscoroutine(coro) and not hasattr(coro, 'cr_code'):
+     if asyncio.iscoroutine(coro) \
+             and not hasattr(coro, 'cr_code') \
+             and not hasattr(coro, 'gi_code'):
+ 
          # Most likely a Cython coroutine
          coro_name = '{}()'.format(coro.__qualname__ or coro.__name__)
+ 
+         running = False
+         try:
+             running = coro.cr_running
+         except AttributeError:
+             try:
+                 running = coro.gi_running
+             except AttributeError:
+                 pass
+ 
-         if coro.cr_running:
+         if running:
              return '{} running'.format(coro_name)
          else:
              return coro_name
  
      return _old_format_coroutine(coro)
  
  
  _old_format_coroutine = coroutines._format_coroutine
  coroutines._format_coroutine = _format_coroutine
  
Fix patched _format_coroutine to support Cython generators
## Code Before:
import asyncio

from asyncio import coroutines


def _format_coroutine(coro):
    if asyncio.iscoroutine(coro) and not hasattr(coro, 'cr_code'):
        # Most likely a Cython coroutine
        coro_name = '{}()'.format(coro.__qualname__ or coro.__name__)
        if coro.cr_running:
            return '{} running'.format(coro_name)
        else:
            return coro_name

    return _old_format_coroutine(coro)


_old_format_coroutine = coroutines._format_coroutine
coroutines._format_coroutine = _format_coroutine

## Instruction:
Fix patched _format_coroutine to support Cython generators
## Code After:
import asyncio

from asyncio import coroutines


def _format_coroutine(coro):
    if asyncio.iscoroutine(coro) \
            and not hasattr(coro, 'cr_code') \
            and not hasattr(coro, 'gi_code'):

        # Most likely a Cython coroutine
        coro_name = '{}()'.format(coro.__qualname__ or 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

    return _old_format_coroutine(coro)


_old_format_coroutine = coroutines._format_coroutine
coroutines._format_coroutine = _format_coroutine
