Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- TIME = 10
- def i_will_run_if_takes_more_time(signum, frame):
- raise Exception("Time has passed. For now i am just printing!")
- # This function *may* run for an indetermined time...
- def i_am_the_main_function():
- while 1:
- print("main funbction is running...")
- time.sleep(1)
- # Register the signal function handler
- signal.signal(signal.SIGALRM, i_will_run_if_takes_more_time)
- # Define a timeout for your function
- signal.alarm(TIME)
- try:
- i_am_the_main_function()
- except Exception as e:
- print(e)
Add Comment
Please, Sign In to add comment