Skip to Main Content
Python Programming On Win32
book

Python Programming On Win32

by Andy Robinson, Mark Hammond
January 2000
Intermediate to advanced content levelIntermediate to advanced
672 pages
21h 46m
English
O'Reilly Media, Inc.
Content preview from Python Programming On Win32

A Final Service

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 ...
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.
Start your free trial

You might also like

Advanced Python Programming - Second Edition

Advanced Python Programming - Second Edition

Quan Nguyen

Publisher Resources

ISBN: 1565926218Supplemental ContentErrata Page