Menu
Coddy logo textTech

Practice #3

Lesson 10 of 12 in Coddy's Python Decorators course.

challenge icon

Challenge

Medium

Write a decorator named rate_limit that limits the rate at which a function can be executed.

The decorator should take a parameter indicating the maximum number of times the function can be called per second. If the function is called more than the maximum number of times per second, the decorator should raise an exception - Exception("Function called too quickly").

Tip: use the <strong>time</strong> library, to get the current time you can use time.monotonic()

The test for this challenge executes a function with this decorator, every 0.2 second, 10 times in total.

Try it yourself

import time

def rate_limit(max_calls):
    # Write code here

All lessons in Python Decorators