Closed maartenbreddels closed 4 years ago
Asyncio ships with two different Futures: The default C-optimized one and a pure-Python one. Since the C future can't be patched, nest_asyncio needs the pure Python one and makes that one the default. So before nest_async.apply(), asyncio.Future will be the C-Future and after the Python one.
So instead of your patch, it should be possible to call nest_asyncio.apply() before importing tornado. Note that your patch also relies on the future having been patched before.
A bit belated, but I've added this idea of patching tornado to nest_asyncio now as well. I did not fully realize before that there are a lot of use cases were tornado is already running and needs to be patched live.
Thank you very much for the code!
Great, happy to see this land in nest_asyncio!
I ran into issues combining this package with tornado:
The problem is tornado keeps a tuple of types that it considers futures. I have this workaround: https://github.com/vaexio/vaex/blob/293d510ef5c8b96ce75224e909a005599c96cc92/packages/vaex-core/vaex/asyncio.py#L5
But maybe you have a better idea for this, or maybe tornado is to blame for this? This line is the issue: https://github.com/tornadoweb/tornado/blob/712d61079defdad23b0a5e9fe0090b54e55cf7d0/tornado/concurrent.py#L49