+ 1

What are async functions in python?

I read a tutorial about async function in Python but i didnt understand :(. Can anyone explain me what async functions are and what is await and event loop? I found this in Discord api tutorials and i dont feel able to make a good discord bot without knowing this.

12th Aug 2018, 9:17 AM
Tim
Tim - avatar
1 Respuesta
+ 3
asynchronous means the function call happens on a thread other than the main one. for example, say you have a sims like game with characters that can perform various actions. and the player types commands to get them to do stuff. In this game you also want to carry on updating the graphics regardless of user input. the only problem is that the input() function is synchronous (doesn't run on another thread) and will wait forever until the user eventually types something and hits enter. until such an event happens, everything in the game will just stop dead in place the solution is to make the event loop (the part that gets user input) asynchronous, it runs on a separate thread, so you can continue updating the graphics while in the background, you're also checking what commands have been entered.
12th Aug 2018, 12:19 PM
Aidan Haddon-Wright
Aidan Haddon-Wright - avatar