Ctrl K
Python · Junior · Theory

Explain how async and await work in Python. What happens if you call a regular time.sleep inside a coroutine?

~4 min by voice

How to approach it

They're checking whether you understand asyncio's cooperative multitasking model: a coroutine itself hands control to the event loop at await points, and any blocking call stops the entire application.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsWrite an async function fetch_all that takes a list of URLs, an async function that fetches a single URL, and a limit on concurrent requests. It returns the results in the same order as the URLs, and a failure of one request must not take down the others. SeniorDesign an aggregator service in FastAPI: for every incoming request it has to call five external services and build a single response from their replies. How do you keep latency low and stay resilient to failures in those services? Mid-levelYou have a FastAPI service, and under load the p99 latency climbs to seconds even though the CPU isn't busy. You suspect the event loop is being blocked. How would you find the cause and fix it? SeniorExplain how the event loop works in JavaScript. And what gets printed to the console if a script has, one after another, a console.log, a setTimeout with zero delay, and a Promise.resolve().then? JuniorA FastAPI service started responding with delays of several seconds under load, even though the CPU is barely used. The endpoints are declared with async def. How would you find the cause? Mid-level

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~4 min