Added signal handler
This commit is contained in:
parent
aa4af27670
commit
1e70edec97
@ -7,6 +7,7 @@ from plugin_repository import PluginRepository
|
||||
from program_executor import ProgramExecutor
|
||||
from http_server import ControllerHTTPServer
|
||||
import logging
|
||||
import signal
|
||||
|
||||
|
||||
class HTTPControl:
|
||||
@ -30,6 +31,7 @@ def main():
|
||||
)
|
||||
http_server = ControllerHTTPServer(HTTPControl())
|
||||
http_server.start()
|
||||
|
||||
compiler_repo = PluginRepository()
|
||||
compiler_repo.register_plugin(WaitPlugin)
|
||||
|
||||
@ -41,8 +43,21 @@ def main():
|
||||
program.append(compiler_repo.get_compiler("wait").compile(secs=10))
|
||||
program.append(compiler_repo.get_compiler("wait").compile(secs=10))
|
||||
|
||||
# execute:
|
||||
executor = ProgramExecutor(program)
|
||||
# prepare execution
|
||||
executor = ProgramExecutor(program, loop=True)
|
||||
|
||||
def handle_stop_signal(signum, frame):
|
||||
logging.warning(f"Signal {signum} received. Stopping execution!")
|
||||
executor.abort()
|
||||
|
||||
# Should be possible to call only once
|
||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
||||
|
||||
signal.signal(signal.SIGINT, handle_stop_signal)
|
||||
signal.signal(signal.SIGTERM, handle_stop_signal)
|
||||
|
||||
# start execution
|
||||
executor.start()
|
||||
|
||||
# End of execution
|
||||
|
Loading…
Reference in New Issue
Block a user