Advanced Lesson 4
Python Decorators
Chapter 3: Using decorators
Example - Timeout
Here is another practical example application of decorators.
Here, I have created a @timeout
decorator that you can wrap around any function to raise a TimeoutError
if the function does not finish executing after a given number of seconds.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|