En Sat, 26 May 2007 23:00:45 -0300, momobear <[EMAIL PROTECTED]> escribió:
> I feel really puzzled about fellowing code, please help me finger out > what problem here. > > import threading > > class workingthread(threading.Thread): > def __init__(self): > self.quitEvent = threading.Event() > self.waitTime = 10 > threading.Thread.__init__(self) > > def run(self): > while not self.quitEvent.isSet(): > self.quitEvent.wait(self.waitTime) > > def join(self, timeout = None): > self.quitEvent.set() > threading.Thread.join(self, timeout) > > 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 = win32event.CreateEvent(None, 0, 0, None) > self.thread = workingthread() > > def SvcStop(self): > win32event.SetEvent(self.hWaitStop) > > def SvcDoRun(self): > self.thread.run() > win32event.WaitForSingleObject(self.hWaitStop, > win32event.INFINITE) > self.thread.join() No, this is not a bug. You must not call Thread.run(), use Thread.start() instead - else your code won't run in a different thread of execution. See http://docs.python.org/lib/thread-objects.html on how to use Thread objects - and note that you should *only* override __init__ and run, if any. 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. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list