Ctrl K
Python · Mid-level · Coding

Write a retry decorator with parameters: the number of attempts, the pause between attempts, and a tuple of exceptions on which to retry. If all attempts end in an error, the last exception should propagate out.

~15 min by voice

How to approach it

They're checking your understanding of decorators with parameters (three levels of nesting) and your carefulness with edge cases: the exact number of calls, filtering exceptions, re-raising the last error instead of a silent None, no unnecessary pause.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsWrite a decorator called timed that measures how long the wrapped function took to run and prints its name and execution time. The function's result should be returned as is, and the arguments can be anything. JuniorWhat is a decorator in Python? How would you write your own decorator, for example one that measures how long a function takes to run? JuniorHow would you write a decorator with parameters, for example a retry with a configurable number of attempts? What are the pitfalls of decorators in production code? SeniorHow do you design error handling in a large Java application: where do you use checked exceptions, where unchecked, and how do errors reach the API client? SeniorTalk me through writing a retry decorator that repeats a function call a given number of times when certain exceptions are raised. How would it be structured, and what pitfalls would you account for? 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 · ~15 min