Hi,
Great idea than one can wrap the node verb function around a decorator to limit the cook time.
Found this tread that help me implement the decorator if anyone else is interested:
https://stackoverflow.com/questions/492519/timeout-on-a-function-call
Test Code for Houdini:
import sys
import threading
from time import sleep
try:
import thread
except ImportError:
import _thread as thread
def quit_function(fn_name):
print(str(fn_name) + ' took too long')
thread.interrupt_main() # raises KeyboardInterrupt
def exit_after(s):
def outer(fn):
def inner(*args, **kwargs):
timer = threading.Timer(s, quit_function, args=[fn.__name__])
timer.start()
try:
result = fn(*args, **kwargs)
finally:
timer.cancel()
return result
return inner
return outer
@exit_after(2)
def countdown(n): # some function that can be run within Python SOP
print('countdown started')
for i in range(n, -1, -1):
print(str(i) + ', ')
sleep(1)
print('countdown finished')
try:
countdown(5)
except:
print('do something else')
Tesekkurler Yunus!