I am encouraging a common problem when mixing sync and async code: calling and waiting for an async function to finish from a standard synchronous function.
def notification(self, news):
result = await process(news) # <- not valid Python
Unfortunately, I cannot make the synchronous function async because it an external library’s function that is calling into my code. Furthermore, this for a desktop application that already has an event loop running, so it’s impossible to do “run_until_complete” on the asyncio event loop.
I wanted to ask for advice here to see if anyone has used Janus to solve this problem?
I was think of starting a thread running a Janus queue when my application starts. When I need to wait for a Coroutine to finish in a synchronous function, my idea was to put that into the queue and wait for it. It will be processed on the other thread and block the calling function until completed.
I really cannot see another way around this without nesting event loops, which I would rather not do, sounds scary.
Any ideas?
--
You received this message because you are subscribed to the Google Groups "aio-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aio-libs+u...@googlegroups.com.
To post to this group, send email to aio-...@googlegroups.com.
Visit this group at https://groups.google.com/group/aio-libs.
To view this discussion on the web visit https://groups.google.com/d/msgid/aio-libs/4f0cb5e9-9d6b-4472-9f9b-5228cfaf28bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks!
I’ll try that. I cannot understand how this works but will try.
If this is called from the UI thread and I pass in the UI thread’s event loop, then does this immediately execute the coroutine on the UI threads loop and block until it is complete?
I think that would be acceptable compromise. Obviously, a better way of doing things would be to block at the calling function but not block the event loop, but I think that might be impossible, without another thread or nested event loop.
What do you think?
--
You received this message because you are subscribed to the Google Groups "aio-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aio-libs+u...@googlegroups.com.
To post to this group, send email to aio-...@googlegroups.com.
Visit this group at https://groups.google.com/group/aio-libs.
To view this discussion on the web visit https://groups.google.com/d/msgid/aio-libs/da2bee38-f6e5-49e9-baf6-b35f6c7409ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.