-
Notifications
You must be signed in to change notification settings - Fork 249
Add basic curio -> asyncio coroutine bridge. #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Interesting. How hard do you think it would be to make this somewhat more like thread/process pools? For a thread-pool, there is a Actually, I'm now almost wondering if this thread pool, process pool, asyncio bridge stuff could be generalized into a more general kernel resource concept. I'm not going to merge this right away, but let me fiddle around with this. Would love to get other's thoughts on it. |
I did have the original idea of making this work within the threadpool rather than a single thread, but I wasn't sure how to work this properly with asyncio's threadsafety requirements. I'll tinker and see if I can make it run inside the |
I'm not sure it needs to run inside thread_pool. I was thinking more about it being initialized/shutdown in a manner similar to how thread pools do it. It could still be a separate thing. |
Oh, okay. This would be possible with a small trivial change. However, there is an impl detail about that: when should the worker loop stop running? Once the asyncio coro has finished running, when the |
I almost wonder if this could be implemented using one of Curio's new-fangled AsyncThread objects. Hopefully you don't mind me thinking out loud about it ;-). |
The |
We are hitting issues at work were we want to do something async but all the existing infrastructure is asyncio only and this is pinching slightly. Something like this could improve the situation. Something that should be importantly considered is the interaction of using curio queues from asyncio code. |
Curious to know a bit more about the "asyncio" functionality you're trying to use. Admittedly, it's probably a bit insane to release a totally new and incompatible I/O library like Curio into the world. I've always considered it to be a bit of a long-play that would take some time to get up to speed on supporting different kinds of services and protocols. |
I'm going to merge this, but may refactor it into using an async thread (which I think might be cleaner). |
I've opened Issue #190 for further discussion of this feature as it evolves, |
This allows you to run asyncio coroutines from within curio, using a new function
curio.acb
(Asyncio Curio Bridge).I put this inside the kernel because it's the easiest and most user-friendly way of co-operating the two event loop types.
The
asyncio
event loop runs inside a thread that is booted whencurio.run()
starts, and stops when it exits. asyncio coroutines are submitted to the worker event loop viarun_coroutine_threadsafe
and the resulting future is then awaited on.Right now, there's no additional tests or documentation.