0
我正在尋找一些退出代碼,將從一個線程運行,但將能夠殺死主腳本。它在Jython中,但我不能使用java.lang.System.exit(),因爲我仍然希望運行Java應用程序,並且sys.exit()不起作用。理想情況下,我想輸出一條消息,然後退出。 我的代碼使用threading.Timer函數在一段時間後運行一個函數。在這裏我使用它來結束執行時間超過1秒的for循環。這裏是我的代碼:Jython如何從線程停止腳本?
import threading
def exitFunct():
#exit code here
t = threading.Timer(1.0, exitFunct)
t.start()
for i in range(1, 2000):
print i
hm理解。那麼你是說沒有辦法從一個線程安全地殺死整個腳本?我只想讓exitFunct能夠殺死腳本,因爲for循環會運行太久。 – 2009-11-25 18:46:17
最初我試圖使用'KeyboardInterrupt',但它不會工作... – 2009-11-25 18:48:50