0
I’m learning asyncio and expected this small example to let the event loop handle other work while the request is waiting. Instead, the second coroutine seems to pause until the first request finishes.
import asyncio
import requests
async def fetch_page(url):
# This synchronous call blocks the event loop while it waits for a response.
response = requests.get(url, timeout=10)
return response.status_code
async def main():
# These tasks are scheduled together, but the blocking call still runs in sequence.
results = await asyncio.gather(
fetch_page("https://example.com"),
fetch_page("https://httpbin.org/delay/2"),
)
print(results)
asyncio.run(main())
Is the issue simply that requests.get is synchronous, even though it sits inside an async def? I’m trying to understand when to use an async HTTP client versus sending blocking work to a thread, especially for a script that needs to fetch many URLs.