Did someone managed to make Cython work with an Asyncio coroutine ? I have a very trivial example that works well in Python, and refuses to work in Cython : it's the following single file that I compile with Cython and execute. The execution starts correctly but fails to run the coroutine. It seems like Cython modifies the type of the "sometask" coroutine, which is then not treated as usual by Asyncio and Inspect.
#!/usr/bin/env python
import asyncio
@asyncio.coroutine
def sometask():
counter = 0
while True:
print(counter)
yield from asyncio.sleep(1)
counter += 1
def runloop():
loop = asyncio.get_event_loop()
asyncio.async(sometask())
try:
print('Start loop')
loop.run_forever()
except KeyboardInterrupt:
print('Aborted by user')
loop.close()
UPDATE : Currently I make it "work" by modifying in an ugly way the asyncio/tasks.py file in places where it checks if the object is a generator, while in fact Cython made it a built-in function. This Cython object will still do the work of an asyncio coroutine, even though it has a different type than expected.
Fortunately, Stefan Behnel made a workaround for this issue in his last version of Cython's master branch.
EDIT : The commit that solves all the issues is c8a2d30806b4e479515d44ee827b3a1651ac8731
A maybe more appropriate solution would be on the Python side, particularly in Asyncio, to identify generators without checking their type. A full solution requires Python 3.4.2 (for sure > Python 3.4.0) Link to more details : https://groups.google.com/forum/#!topic/cython-users/g146SZHxRyM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With