gfmio/asyncio-gevent

example for asyncio on gevent does not work

FelixSchwarz opened this issue · 2 comments

I tried to run the example to run "asyncio on gevent" but it does not work for me:

import gevent.monkey
gevent.monkey.patch_all()
import asyncio
import asyncio_gevent
# example in README.md uses:
#   asyncio.set_default_event_loop_policy(asyncio_gevent.EventLoopPolicy)
# however this function does not exist in Python 3.9
asyncio.set_event_loop_policy(asyncio_gevent.EventLoopPolicy())

async def async_function() -> int:
    await asyncio.sleep(1)
    return 42

def main() -> None:
    future = async_function()
    # blocking in ".yield_future()"
    greenlet = asyncio_gevent.yield_future(future)
    greenlet.join()

main()

Initially I noticed that asyncio.set_default_event_loop_policy() does not exist for me (Fedora 34, Python 3.9). I used .set_event_loop_policy() but then execution blocks in yield_future().

I guess got the initialization wrong somehow but I can't figure out what is wrong here...

gfmio commented

Hey!

Thanks for filing this issue and sorry for the delay in responding to it.

Yes, you’re completely right, the implementation was partially broken and the docs were wrong.

I think I just fixed all of this is #3 (version 0.2.0). Do you want to give it a try and let me know if it works for you now?

If you run into more issues, please report them. If you’d like to contribute fixes, then PRs are also welcome. Any help is greatly appreciated!

gfmio commented

Closing this as I haven't received any further error reports about this.