i am wondering whether this is possible to do in Python 3.x
i have a function in a class that is quite long (time wise), it takes a few minutes to finish running. I am wondering whether I can force it to stop with an exception. But I want to have control of that exception so that I can trigger it any time.
A trivial solution, would be to check for my order x, if it is true I raise an exception and put this code at key points in the function. However this is tedious for long functions. But I am wondering whether there is a more efficient way to do it. something like wrapping the function with some custom library that can do this (periodically checks for x, and throws an exception to force the function to stop)
def function():
...
if x:
raise Exception
...
if x:
raise Exception
...
if x:
raise Exception
...
Thank you