a bug in python windows service?
momobear
wgwigw at gmail.com
Mon May 28 10:05:31 EDT 2007
On May 27, 11:25 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Sun, 27 May 2007 09:07:36 -0300, momobear <wgw... at gmail.com> escribió:
>
> >> Instead of extending join(), write a specific method to signal the
> >> quitEvent or just let the caller signal it. And I don't see in this
> >> example why do you need two different events (one on the thread, another
> >> on the service controller), a single event would suffice.
>
> > I don't think a single event is enought, since I think the event
> > python created and windows event are not same kind of event.
>
> They are not the same object, of course (altough the threading.Event
> object relies eventually on a mutex implemented using CreateEvent). But in
> this case both can be successfully used; of course, having the Python
> object a more "pythonic" interfase (not a surprise!), it's easier to use.
> The same example modified using only a threading.Event object (and a few
> messages to verify how it runs):
>
> import threading
> from win32api import OutputDebugString as ODS
>
> class workingthread(threading.Thread):
> def __init__(self, quitEvent):
> self.quitEvent = quitEvent
> self.waitTime = 1
> threading.Thread.__init__(self)
>
> def run(self):
> while not self.quitEvent.isSet():
> ODS("Running...\n")
> self.quitEvent.wait(self.waitTime)
> ODS("Exit run.\n")
>
> import win32serviceutil
> import win32event
>
> class testTime(win32serviceutil.ServiceFramework):
> _svc_name_ = "testTime"
> _svc_display_name_ = "testTime"
> _svc_deps_ = ["EventLog"]
>
> def __init__(self, args):
> win32serviceutil.ServiceFramework.__init__(self, args)
> self.hWaitStop = threading.Event()
> self.thread = workingthread(self.hWaitStop)
>
> def SvcStop(self):
> self.hWaitStop.set()
>
> def SvcDoRun(self):
> self.thread.start()
> self.hWaitStop.wait()
> self.thread.join()
>
> if __name__ == '__main__':
> win32serviceutil.HandleCommandLine(testTime)
>
> --
> Gabriel Genellina
Great! thanks, now I understand the real work of the python windows
service.
More information about the Python-list
mailing list