\core\local\cli\shutdown::script_supports_graceful_exit();
Sets up interception of exit signals and keep the script running.
\core\local\cli\shutdown::should_gracefully_exit();
Use this to check whether you should exit, often inside a long running loop.