I want to have a function, in Python (3.x), which force to the script itself to terminate, like :
i_time_value = 10
mytimeout(i_time_value ) # Terminate the script if not in i_time_value seconds
for i in range(10):
print("go")
time.sleep(2)
Where "mytimeout" is the function I need : it terminate the script in "arg" seconds if the script is not terminated.
I have seen good solutions for put a timeout to a function here or here, but I don't want a timeout for a function but for the script.
Also :
- I know that I can put my script in a function or using something like subprocess and use it with a timeout, I tried it and it works, but I want something more simple.
- It must be Unix & Windows compatible.
- The function must be universal i.e. : it may be add to any script in one line (except import)
- I need a function not a 'how to put a timeout in a script'.