Add support for other event loops - #1
Conversation
a5d3f3f to
9cd8f68
Compare
9cd8f68 to
2d40a6c
Compare
|
thank you @davidbrochart! I think this is great.
that's fine with me, it's similar (in spirit) to the
Also works for me. I also wouldn't be opposed to depending on or vendoring the tiny sniffio if you think it would generally just do the right thing without requiring the psygnal user to have to call Thanks a bunch for this pattern. I'm happy to merge it and polish it up with some tests and ping you for feedback (unless you want to do that yourself and make a PR?) |
Hmm I don't think that would work, because we would not detect AnyIO, which doesn't have an event loop per say (it itself uses a Trio or an asyncio backend), yet AnyIO's API is different than Trio's.
Thanks, that works for me 😄 |
|
ok sounds good! |
Sorry for the long silence @tlambert03. This is what I have in mind for supporting other event loops than asyncio. Right now it only adds support for AnyIO, but we could add Trio too (if people want to use Trio not through AnyIO).
Basically, users have to call
set_async_backend()with the backend of their choice ("asyncio"or"anyio"). This should be done as early as possible, and only once. It means this PR only supports one global event loop, which I think is good enough, but we could improve it to support multiple event loops in the future.Then users must launch the
get_async_backend().runcoroutine in a background task. This part is event-loop specific. For asyncio, that would beasyncio.create_task(get_async_backend().run()). For AnyIO, that would betg.start_soon(get_async_backend().run), supposing they got a task grouptgsomehow.Let me know what you think. The PR is not polished but this is the idea.