How does a context manager work under the hood? What happens to an exception inside a with block, and how would you write a manager that handles a database transaction?
~4 min by voice
How to approach it
This checks whether you understand the context manager protocol: how with calls __enter__ and __exit__, and how an exception passes through __exit__ and gets suppressed. Second, whether you can apply it to a real task: a transaction with commit and rollback, nesting and async.
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.