Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Accept generator created in Cython #233

Closed

Description

@methane

Problem was reported here: https://groups.google.com/forum/#!topic/cython-users/g146SZHxRyM
I think supporting Cython is very important for asyncio performance.

Activity

  1. gvanrossum commented on Apr 20, 2015

    @gvanrossum
    Member

    Agreed, I would gladly accept patches. I'm not a Cython user myself so I can't fix this without help.

  2. ludovic-gasc commented on Apr 20, 2015

    @ludovic-gasc
    Member

    Hi @methane, thank you for the link.
    On the mailing-list, Stefan seems to find a solution: cython/cython@4af4244
    I've played my role of messenger: I've invited him to open a pull request.

  3. scoder commented on Apr 20, 2015

    @scoder

    I had already created a CPython ticket for this:

    https://bugs.python.org/issue24004

    Here's what Cython currently (as in "since yesterday") does in order to circumvent the type checks in asyncio and inspect:

    https://github.com/cython/cython/blob/4af42443bd37f6207143f8870904f780a65bb3e3/Cython/Utility/Generator.c#L824

    https://github.com/cython/cython/blob/4af42443bd37f6207143f8870904f780a65bb3e3/Cython/Utility/Generator.c#L906

    It's not clear to me what the best fix is here, but my gut feeling tells me that the correct way to deal with this is to create a Generator ABC and do the type checking based on that. A "Generator" is an object that implements the Generator protocol, not necessarily something of type types.GeneratorType. Special casing that type is fine, obviously, but excluding everything else isn't.

    The fact that this crash bug here went unnoticed since Py3.3 makes it obvious, though, that no-one has ever tried this at the C level:

    https://bugs.python.org/issue23996

  4. methane commented on Apr 20, 2015

    @methane
    MemberAuthor

    I think adding Coroutine ABC to somewhere is good way to solve this problem.
    It may be in the stdlib. But I think we should wait discussion of async/await syntax.

    For now, how about asyncio.coroutines.Coroutine ?

    from abc import ABCMeta, abstractmethod
    import types
    
    
    class Coroutine(metaclass=ABCMeta):
        def __iter__(self):
            return self
    
        def __next__(self):
            raise StopIteration
    
        @abstractmethod
        def send(self):
            raise StopIteration
    
    
    Coroutine.register(types.GeneratorType)
    Coroutine.register(CoroWrapper)
    
    
    def iscoroutine(obj):
        """Return True if obj is a coroutine object."""
        return isinstance(obj, Coroutine)
  5. 1st1 commented on May 13, 2015

    @1st1
    Member

    @scoder You can now use collections.abc.Coroutine for your purposes (3a09a93). Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy