January 2000
Intermediate to advanced
672 pages
21h 46m
English
We have made a number of changes to the sample service since first presented. Here’s the full source code:
# PipeService2.py # # A sample demonstrating a service which uses a # named-pipe to accept client connections, # and writes data to the event log. import win32serviceutil import win32service import win32event import win32pipe import win32file import pywintypes import winerror import perfmon import os class PipeService(win32serviceutil.ServiceFramework): _svc_name_ = "PythonPipeService" _svc_display_name_ = "A sample Python service using named pipes" def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) # Create an event which we will use to wait on. # The "service stop" request will set this event. self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) # We need to use overlapped IO for this, so we dont block when # waiting for a client to connect. This is the only effective way # to handle either a client connection, or a service stop request. self.overlapped = pywintypes.OVERLAPPED() # And create an event to be used in the OVERLAPPED object. self.overlapped.hEvent = win32event.CreateEvent(None,0,0,None) # Finally initialize our Performance Monitor counters self.InitPerfMon() def InitPerfMon(self): # Magic numbers (2 and 4) must match header and ini file used # at install - could lookup ini, but then Id need it a runtime # A counter for number of connections per second. self.counterConnections=perfmon.CounterDefinition(2) # We ...