On Jun 19, 12:32 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 19 Jun 2007 14:57:10 -0300, <[EMAIL PROTECTED]> escribió:
>
> >> >         #win32event.WAIT_TIMEOUT = 2 --- This just makes the loop
> >> > never execute because
> >> >         # the WaitFor... part always returns 258
>
> >> WAIT_TIMEOUT is 258. How do you see it is 2?
> >> py> import win32event
> >> py> win32event.WAIT_TIMEOUT
> >> 258
>
> > I meant here that *if* I set the WAIT_TIMEOUT to 2, then I see that
> > behavior.
>
> Ah, ok! I should have stated clearly that WAIT_TIMEOUT is a Windows  
> predefined constant, not your desired timeout value.
>
> > Thank you again Gabriel.  I'll post back with something complete.
>
> Yes, please, a working example would be nice for future readers...
>
> --
> Gabriel Genellina

For posterity...

import sys
import win32serviceutil
import win32service
import win32event
import win32evtlogutil
import servicemanager

import SocketServer, socket
from SimpleXMLRPCServer import
SimpleXMLRPCServer,SimpleXMLRPCRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer):
pass

import XMLRPC_funcs # module containing the functions wrapped in a
class

class XMLRPCservice(win32serviceutil.ServiceFramework):
    _svc_name_ = "PythonXMLRPC"
    _svc_display_name_ = "PythonXMLRPC"
    _svc_description_ = "Multi-threaded Python XMLRPC Server"

    def __init__(self, args):
        # set the timeout so the service can stop...Otherwise it hangs
forever
        socket.setdefaulttimeout(15)

        win32evtlogutil.AddSourceToRegistry(self._svc_display_name_,
sys.executable, "Application")
        win32serviceutil.ServiceFramework.__init__(self, args)

        # Create an event which we will use to wait on.
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
        localhost = socket.gethostbyname(socket.gethostname())
        self.server = AsyncXMLRPCServer((localhost, 8000),
SimpleXMLRPCRequestHandler)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        #send the stop event
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        # log a start msg
 
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_, ' (%s)' %
self._svc_name_))

        self.server.register_instance(XMLRPC_funcs.XMLRPC_funcs())

        # handle requests until the stop event is received
        while win32event.WaitForSingleObject(self.hWaitStop, 0) ==
win32event.WAIT_TIMEOUT:
            self.server.handle_request()

        # log a stopped msg
        win32evtlogutil.ReportEvent(self._svc_name_,
                                    servicemanager.PYS_SERVICE_STOPPED,
0,
 
servicemanager.EVENTLOG_INFORMATION_TYPE,
                                    (self._svc_name_,""))

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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to