[1.0.1] Why does exit() only work half of the time?

Asked by Zebara

I use exit() in a hotkey and it stops the Sikuli program half of the time. However, whenever I press the hotkey all the other code in it is always executed successfully. How can I fix this to make the Sikuli program stop every time I press the hotkey?

Here is the hotkey:

def stopSikuli(event):
    print("stopSikuli")
    logger.warning("stopSikuli executed")
    stopLogging(logger, hdlr, log_name)
    Env.removeHotkey("c", KeyModifier.CTRL)
    exit(1)

I initialize the hotkey later with:

Env.addHotkey("c", KeyModifier.CTRL, stopSikuli)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
RaiMan Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

might have something to do with the force and back implementation of the callback function between the Jython and the Java level.

instead of exit() try this

# at beginning of script:
import java.lang.System as JSys

# as exit(1)
SikuliX.cleanUp(0)
JSys.exit(1)

which definitely should stop the JVM.

Revision history for this message
Zebara (kbrennan56) said :
#2

Thanks RaiMan!

I used the following and it worked perfectly:

Env.cleanUp()
JSys.exit(1)