O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ServiceCtrlHandler as 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 SvcPause method, 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 a SvcDoRun method in the subclass that handles the functionality of your service.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required