Hi, Celelibi, Welcome to Python Ideas.
Python Dev is more for discussions of implementations of proposed features, typically clearly on their way to an accepted pull request into master. Python-Ideas is a better place for a request for enhancement without an implementation patch, so I'm moving it here. You're also more likely to get discussion here. Celelibi writes: > Hello world, > > I always knew asynchronous programming is awesome. And having a language > support for it really help its adoption by limiting the existence of > incompatible event frameworks which would be a pain to use together. > > However, the asynchronousness is very contaminating. Yes. I would expect that. > This makes it difficult to make threads and asyncio coexist in a > single application True. Do you know of a programming environment that makes it easy that we can study? > Unless I'm mistaken, there's no obvious way to have a function run a > coroutine in a given event loop, no matter if the loop in running or > not, no matter if it's running in the current context or not. > There are at least 3 cases that I can see: > 1) The loop isn't running -> run_until_complete is the solution. > 2) The loop is running in another context -> we might use > call_soon_threadsafe and wait for the result. > 3) The loop is running in the current context but we're not in a > coroutine -> there's currently not much we can do without some major > code change. > > What I'd like to propose is that run_until_complete handle all three > cases. I don't see how the three can be combined safely and generically. I can imagine approaches that might work in a specific application, but the general problem is going to be very hard. async programming is awesome, and may be far easier to get 100% right than threading in some applications, but it has its pitfall too, as Nathaniel Smith points out: https://vorpus.org/blog/some-thoughts-on-asynchronous-api-design-in-a-post-asyncawait-world/ > Did I miss an obvious way to make the migration from threads to asyncio > easier? Depends on what your threads are doing. If I were in that situation, I'd probably try to decouple the thread code from the async code by having the threads feed one or more queues into the async code base, and vice versa. > It becomes harder and harder to not believe that python is purposfully > trying to make this kind of migration more painful. Again, it would help a lot if you had an example of known working APIs we could implement, and/or more detail about your code's architecture to suggest workarounds. Regards, Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/64MAHECURBGZHQZZ6DJR3TKWJBVNOMMC/ Code of Conduct: http://python.org/psf/codeofconduct/