I'd like to monitor a process and auto-kill it if it runs more than N seconds.
I'm editing this question in response to the suggestion that it's a duplicate of: Is there any way to kill a Thread in Python?
I'd argue that my question is slightly different in that I'm focused on basic cleanup AFTER thread completion (which might actually be more difficult than the aforementioned possible duplicate as everyone seems to say it's impossible).
As a simple test, I'm attempting the following to try and kill the process after 2 seconds:
import threading
import sys
import time
def after_timeout():
print "KILL THE WORLD HERE!"
# whats the secret sauce here (if any)?
# sys.exit() and other variants aren't
# killing the main thread... is it possible?
threading.Timer(2, after_timeout).start()
i = 0
while True:
print i
i += 1
time.sleep(1)