views:

18

answers:

1

Whenever the code thread.interrupt_main() is used in Jython it doesn't actually interrupt the main thread. Any ideas as to alternatives? Code is below:

import threading
import dummy_thread as _thread
def exitFunct():
    _thread.interrupt_main()
t = threading.Timer(60.0, exitFunct)
t.start()
for i in range(1, 3000):
    print i
A: 

Does listing 3000 numbers take longer than 60 seconds on your machine? Looks like main is finished before the timer will fire so nothing to interrupt anymore as main already has exited. No?

You could also try using PyErr_SetInterrupt() instead.

jitter
thanks but that isn't working. I need it to interrupt and stop the main thread in Jython. Regarding the listing 3000 numbers, I just mean that exitFunct will need to execute before the main thread is finished executing.