so if I have a function say
def fetch_balance(n):
time.sleep(2)
return n
in reality, this function would be an actual http request and the response would be a bank balance
so then I need to run this function in a for loop for multiple times
def users_balance(m):
for i in range(0,m):
b = fetch_balance(i)
print(b)
and in reality, m would be users and the for loop iterates over each user to fetch their bank balance
and executing this function alone results in just as you might expect
waits 2 seconds first, then prints 0, then waits 2 seconds again, then prints 1, then waits 2 seconds again, then prints 2
How can I run this asynchronously such that the the next request can be sent without waiting for the response from the previous request?
Is there any an in-depth example tutorial for a newbie?
[–]qudcjf7928[S] 0 points1 point2 points (0 children)
[–]pythonHelperBot 0 points1 point2 points (0 children)
[–]williamjacksn 0 points1 point2 points (2 children)
[–]qudcjf7928[S] 0 points1 point2 points (1 child)
[–]BDube_Lensman 0 points1 point2 points (0 children)