DEV Community

Discussion on: Async programming in Python with asyncio

Collapse
 
mtoto_lekgwathi profile image
Mapogo Lekgwathi

I think this is somewhat unhelpful, what if I write mainly synchronous code and want some tasks to execute asynchronously? (I don't care about what the async function returns)

E.g I want to run a http request in the background every time something happens, but I don't want to create a thread, and run it

Collapse
 
welldone2094 profile image
Andrea Benfatti

unfortunately, I think that what you are asking is not possible, if the program runs in a single process/thread it needs to know when to switch between tasks. I think for your problem the best solution is to use multiple threads which make the code really simple and you don't need to decide when to switch context with just minimal overhead.