Why Can an Async Python Handler Still Block Other Requests?

Asked 5 days ago 102 views

0

I’m trying to understand a slowdown in a small async Python service. One handler makes a request to another API, and while that call is waiting, unrelated requests seem to take longer too.

import requests

async def get_profile(user_id):
    # This synchronous call waits for the remote server and blocks the event loop.
    response = requests.get(f"https://example.com/users/{user_id}")
    # Parse the response after the blocking network call finishes.
    return response.json()

I thought marking the function async would let the server handle other work during the wait. Is the blocking network call the reason that isn’t happening, or am I missing something about how async handlers are scheduled?

0 Answers


Write Your Answer