Reputation: 11
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
Upvotes: 1
Views: 1538
Reputation: 6949
If you want to kill the current process and you don't care about flushing IO buffers or reseting the terminal, you can use os._exit()
.
I don't know why they made this so hard.
Upvotes: 0
Reputation: 45086
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.
Upvotes: 1