views:

194

answers:

1

I'm looking for some exit code that will be run from a thread but will be able to kill the main script. It's in Jython but I can't use java.lang.System.exit() because I still want the Java app I'm in to run, and sys.exit() isn't working. Ideally I would like to output a message then exit. My code uses the threading.Timer function to run a function after a certain period of time. Here I'm using it to end a for loop that is executing for longer than 1 sec. Here is my code:

import threading
def exitFunct():
    #exit code here
t = threading.Timer(1.0, exitFunct)
t.start()
for i in range(1, 2000):
    print i
A: 

Well, if you had to, you could call mainThread.stop(). But you shouldn't.

This article explains why what you're trying to do is considered a bad idea.

Jason Orendorff
hm understood. so are you saying there is no way to safely kill the whole script from a thread? I just want the exitFunct to be able to kill the script since the for loop will be running for too long.
JJ
originally I tried to use 'KeyboardInterrupt' but it wouldn't work either...
JJ