Here the first iterations of the loop will be able to perform the expensive
operation, until the shared quota of 1 second runs out and then the remaining
iterations will perform the cheaper alternative.

A single quota instance can also be shared across all calls to timeout()
your application makes (including nested calls), to give place an upper bound
on the total runtime, regardless of how many calls to timeout() you have.

Caveats

Interruptingcow uses signal(SIGALRM) to let the operating system interrupt
program execution. This has the following limitations:

Python signal handlers only apply to the main thread, so you cannot use this
from other threads

You must not use this in a program that uses SIGALRM itself (this
includes certain profilers)