The Anatomy of a Python Service
The same executable hosts most Python services, PythonService.exe . This special executable is aware of the special requirements for services that make Python.exe unsuitable for the task.
When PythonService.exe is asked to start a
service, it looks in the registry for the Python class that
implements the service. It then creates an instance of this class,
and delegates all service functionality to this instance. For
example, when the service is to start, a method named
SvcStart is called on the object. When the SCM
makes a control request, a method named
ServiceControlHandler is called. These Python
methods are expected to correctly report their status to the SCM, by
calling helper functions provided by
PythonService.exe.
To make life as simple as possible for the Python programmer, a base
class ServiceFramework is provided in the module
win32serviceutil
. The easiest way to write a service in
Python is to subclass this class, then concentrate on the service
functionality rather than on the interactions with the SCM.
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