Added signal handler
This commit is contained in:
		@@ -7,6 +7,7 @@ from plugin_repository import PluginRepository
 | 
				
			|||||||
from program_executor import ProgramExecutor
 | 
					from program_executor import ProgramExecutor
 | 
				
			||||||
from http_server import ControllerHTTPServer
 | 
					from http_server import ControllerHTTPServer
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					import signal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HTTPControl:
 | 
					class HTTPControl:
 | 
				
			||||||
@@ -30,6 +31,7 @@ def main():
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
    http_server = ControllerHTTPServer(HTTPControl())
 | 
					    http_server = ControllerHTTPServer(HTTPControl())
 | 
				
			||||||
    http_server.start()
 | 
					    http_server.start()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    compiler_repo = PluginRepository()
 | 
					    compiler_repo = PluginRepository()
 | 
				
			||||||
    compiler_repo.register_plugin(WaitPlugin)
 | 
					    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))
 | 
				
			||||||
    program.append(compiler_repo.get_compiler("wait").compile(secs=10))
 | 
					    program.append(compiler_repo.get_compiler("wait").compile(secs=10))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # execute:
 | 
					    # prepare execution
 | 
				
			||||||
    executor = ProgramExecutor(program)
 | 
					    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()
 | 
					    executor.start()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # End of execution
 | 
					    # End of execution
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user