+ 2
‘async’ keyword
Hi- I have seen some code on GitHub for python, and it has the async keyword before the def function keyword, so i was wondering what this meant as i am still like 15 percent done with py intermediate ❤️
2 Respuestas
+ 3
interlinked keyword => git, git hub, py, python.
async => asynchronous.,
+ 1
leo, using the async keyword like this:-
async def func():
means that this is an asynchronous function (or a coroutine).
Unlike normal functions, an async function can pause its execution at certain points and let other tasks run in the meantime, before continuing later.
See, Python, in normal cases, is executed synchronously i.e., line by line. This is fine for many tasks, but it can cause problems when your program needs to wait for something slow because, in such a fase, the program would freeze until the slow task finishes. With async code, on the other hand, Python can switch to other tasks while it’s waiting, thereby making your program faster.
Basically, with async code the program kewps running while it is waiting, instead of freezing.
Feel free to let mw know if you need further clarification.
Thank you.