Replies: 2 comments
-
We didn't artificially prevent use of the two, but we don't test the scenario. The general feeling was that async can be tricky for developers (you) to use the correct coding style eg. |
Beta Was this translation helpful? Give feedback.
-
It is generally important to ensure that only async-aware APIs are used with asyncio; otherwise, the event loop is blocked and won't allow other coroutines to be processed while the blocking API is executing (or waiting). If you want to use both sync and async APIs concurrently, then you have more work cut out for you and additional complexities to navigate! You can create an event loop, process a bunch of coroutines and then shut down the event loop -- this is likely the simplest approach and works fairly well. There is some overhead involved in the setup and teardown of the event loop but I believe it is manageable. You can try to create the event loop in a separate thread and leave it there permanently -- but I'm not sure myself how feasible that is and how much overhead you would save if it was feasible! Other possibilities may exist, of course -- but they are not commonly used, which means you are generally on your own. If you have converted most of your code to use asyncio, you can use the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The Concurrent Programming with asyncio documentation states:
Would anyone be able to elaborate on this a bit?
Why is it not recommended? Is there specific cases where it would be bad but otherwise would be fine?
In my particular case, I have a sync application and want to use the sync API for the vast majority of the time. However, there are a few cases where inside of a sync thread, I need to make multiple independent queries to the database, and would like to be able to run these three concurrently in an event loop, instead of launching three threads.
Off the top of my head I can not think of any reason why it would be bad to use both sync and async APIs in the same code base.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions