Extend the Controller class with your own application implementing the Controller.process method. If you do not want to use sleep based looping but rather an IOLoop or some other long-lived blocking loop, redefine the Controller.run method.
Controller maintains an internal state which is handy for ensuring the proper things are happening at the proper times. The following are the constants used for state transitions:
When extending Controller, if your class requires initialization or setup setups, extend the Controller.setup method.
If your application requires cleanup steps prior to stopping, extend the Controller.cleanup method.
Extend this class to implement your core application controller. Key methods to implement are Controller.setup, Controller.process and Controller.cleanup.
If you do not want to use the sleep/wake structure but rather something like a blocking IOLoop, overwrite the Controller.run method.
When shutting down, how long should sleeping block the interpreter while waiting for the state to indicate the class is no longer active.
The active state should be set whenever the implementing class is performing a task that can not be interrupted.
The idle state is available to implementing classes to indicate that while they are not actively performing tasks, they are not sleeping. Objects in the idle state can be shutdown immediately.
Initializing state is only set during initial object creation
When helper has set the signal timer and is paused, it will be in the sleeping state.
Once the application has fully stopped, the state is set to stopped.
Once the application has started to shutdown, it will set the state to stopping and then invoke the Controller.stopping() method.
The stop requested state is set when a signal is received indicating the process should stop. The app will invoke the Controller.stop() method which will wait for the process state to change from STATE_ACTIVE
How often should Controller.process() be invoked
Override this method to cleanly shutdown the application.
Override to provide any steps when the configuration is reloaded.
Property method that return the string description of the runtime state.
Return type: | str |
---|
Property method that returns a bool specifying if the process is currently active.
Return type: | bool |
---|
Property method that returns a bool specifying if the process is currently idle.
Return type: | bool |
---|
Property method that returns a bool specifying if the process is currently initializing.
Return type: | bool |
---|
Property method that returns a bool specifying if the process is currently running. This will return true if the state is active, idle or initializing.
Return type: | bool |
---|
Property method that returns a bool specifying if the process is currently sleeping.
Return type: | bool |
---|
Property method that returns a bool specifying if the process is stopped.
Return type: | bool |
---|
Property method that returns a bool specifying if the process is stopping.
Return type: | bool |
---|
Property method that returns a bool specifying if the process is waiting for the current process to finish so it can stop.
Return type: | bool |
---|
Called when SIGHUP is received, shutdown internal runtime state, reloads configuration and then calls Controller.run(). Can be extended to implement other behaviors.
Called when SIGTERM is received, calling self.stop(). Override to implement a different behavior.
Called when SIGUSR1 is received, does not have any attached behavior. Override to implement a behavior for this signal.
Called when SIGUSR2 is received, does not have any attached behavior. Override to implement a behavior for this signal.
To be implemented by the extending class. Is called after every sleep interval in the main application loop.
The core method for starting the application. Will setup logging, toggle the runtime state flag, block on loop, then call shutdown.
Redefine this method if you intend to use an IO Loop or some other long running process.
Set the runtime state of the Controller. Use the internal constants to ensure proper state values:
Parameters: | state (int) – The runtime state |
---|---|
Raises : | ValueError |
Override to provide any required setup steps.
Override to provide any required shutdown steps.
Important:
Do not extend this method, rather redefine Controller.run
Override to implement shutdown steps.
Return a tuple containing the operating system, python implementation (CPython, pypy, etc), and python version.
Return type: | tuple(str, str, str) |
---|
Property method that returns the wake interval in seconds.
Return type: | int |
---|