Is it possible to have some function that increments a counter run upon each instruction within a function, and does some behavior if a number is reached?
To explain, I want to be able to raise an exception if a function ends up taking up past a certain number of bytecode instructions in the virtual machine. So, if someone creates a list comprehension that will make an infinite loop, or creates an infinite while loop, it will force a break out early.
Can this be done in Python?