Critical Exit API

Safety mechanism to forcibly terminate automation scripts via a hotkey.


CriticalExit

class CriticalExit(default_daemon=True)

A daemon thread that monitors a keyboard key and interrupts the main thread when pressed. Inherits from threading.Thread.

Parameters:

default_daemon (bool) – Whether the thread runs as a daemon. Defaults to True.

The default interrupt key is F7.

set_critical_key(keycode=None)

Changes the hotkey used to trigger the critical exit.

Parameters:

keycode (int or str) – New key name or key code. If None, no change is made.

Example:

critical = CriticalExit()
critical.set_critical_key("escape")
run()

The thread’s main loop. Continuously checks if the exit key is pressed and calls _thread.interrupt_main() when detected.

Warning

Do not call run() directly. Use init_critical_exit() instead.

init_critical_exit()

Starts the critical exit monitoring thread. This is the recommended way to enable critical exit.

Example:

from je_auto_control import CriticalExit

CriticalExit().init_critical_exit()