The win32serviceutil.ServiceFramework Class
As described previously, most Python services will be a subclass of
the
win32serviceutil.ServiceFramework
class. This has a number of default
methods and helper methods to make writing services in Python easier:
-
__init__ The constructor for the class. This registers the method
ServiceCtrlHandleras the handler for notification messages from the SCM.-
ServiceCtrlHandler Provides a default implementation of the service control handler. This method interrogates the class for certain named methods to determine which controls the service responds to. For example, if the service contains a
SvcPausemethod, it’s assumed the service can be paused.-
SvcRun A default implementation of the entry point for the service. This method notifies the SCM that the service has started, calls a method
SvcDoRun, then when complete notifies the SCM the service is stopping (PythonService.exe automatically notifies the SCM that the service has stopped). Thus, you need only provide aSvcDoRunmethod in the subclass that handles the functionality of your service.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access