MCPcopy Create free account
hub / github.com/bugy/script-server / signal_handler

Function signal_handler

src/web/server.py:768–791  ·  view source on GitHub ↗
(signum, frame)

Source from the content-addressed store, hash-verified

766
767def intercept_stop_when_running_scripts(io_loop, execution_service):
768 def signal_handler(signum, frame):
769 can_stop = True
770
771 running_processes = execution_service.get_running_executions()
772 if len(running_processes) > 0:
773 try:
774 user_input = input('Some scripts are still running. Do you want to stop server anyway? Y/N: \n')
775 can_stop = (user_input.strip().lower()[0] == 'y')
776 except EOFError:
777 # EOF happens, when input is not available (e.g. when run under systemd)
778 LOGGER.warning('Some scripts are still running, killing them forcefully')
779 can_stop = True
780
781 if can_stop:
782 try:
783 LOGGER.info('Killing the running processes: ' + str(running_processes))
784 for id in running_processes:
785 execution_service.kill_script_by_system(id)
786 except:
787 LOGGER.exception('Could not kill running scripts, trying to stop the server')
788
789 if can_stop:
790 LOGGER.info('Stopping server on interrupt')
791 io_loop.add_callback_from_signal(io_loop.stop)
792
793 signal.signal(signal.SIGINT, signal_handler)
794

Callers

nothing calls this directly

Calls 2

kill_script_by_systemMethod · 0.80

Tested by

no test coverage detected