For example, I have a code like the following code in Python.
import time
def sleep(timeout: int) -> str:
time.sleep(timeout ** 7 * 1000)
return "Hello, world!"
result = sleep(5)
As you know, this code is very time consuming. I want to make it so that if the execution of the code takes more than 5 seconds, it will stop the execution and return a message like "function stopped". How can I do this?
I used different things in Python such as time, thread and signal, but I did not get the result I wanted and the program crashes.