Windows XMLRPC Service

half.italian at gmail.com half.italian at gmail.com
Sun Jun 17 23:25:25 EDT 2007


Hi,

I'm trying to serve up a simple XMLRPC server as a windows service.  I
got it to run properly, I'm just not sure how to stop it properly.
Most of the documentation/examples I found for this was from forums,
so I'd love some links to relevant info also.  Here's what I
have...taken from the cookbook with the xmlrpc server added:

import win32serviceutil
import win32service
import win32event

import SimpleXMLRPCServer

class MyClass(object):
    def hello(self):
        return "Hello World!"

class SmallestPythonService(win32serviceutil.ServiceFramework):
    _svc_name_ = "PythonXMLRPC"
    _svc_display_name_ = "PythonXMLRPC"

    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)

    def SvcStop(self):
        # Before we do anything, tell the SCM we are starting the stop
process.
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)

        # quit the xmlrpc sever
        self.server.quit()

        # And set my event.
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        # Serve up the XMLRPC forever
        self.server =
SimpleXMLRPCServer.SimpleXMLRPCServer(("10.0.1.6", 8000))
        self.server.register_instance(MyClass())
        self.server.serve_forever()

        win32event.WaitForSingleObject(self.hWaitStop)


if __name__=='__main__':
    win32serviceutil.HandleCommandLine(SmallestPythonService)

~Sean




More information about the Python-list mailing list