On Jun 19, 10:21 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 19 Jun 2007 03:45:19 -0300, <[EMAIL PROTECTED]> escribió:
>
> > I can't quite figure out where to set the "socket timeout".  I tried
> > setting win32event.WAIT_TIMEOUT, but I'm pretty sure that's not the
> > variable you were talking about.  I did manage to make it multi-
> > threaded by incorporating a different recipe, and I'm beginning to
> > understand the control flow a bit better, but it doesn't seem to be
> > doing what I expect.  When SvcStop() is executed and calls
> > win32event.SetEvent(self.hWaitStop), the while loop should break as
> > win32event.WaitForSingleObject(self.hWaitStop, 0) returns zero at this
> > point.  But it doesn't do that.  What am I missing?
>
> May be because you didn't set correctly the socket timeout. See the  
> comments below.
>
>
>
> >     def SvcStop(self):
> >         self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
> >         win32event.SetEvent(self.hWaitStop)
> >         #print "EVENT:",
> > win32event.WaitForSingleObject(self.hWaitStop, 0) # returns 0 here
>
> That's OK, since you have set the event.
>
> >     def SvcDoRun(self):
> >         self.server.register_instance(MyClass())
>
> >         #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?
> For example, see <http://msdn2.microsoft.com/en-us/library/ms681382.aspx>.
> Python 2.5.1 + pywin32 210 prints this on my PC:
> py> import win32event
> py> win32event.WAIT_TIMEOUT
> 258
>
> >         while win32event.WaitForSingleObject(self.hWaitStop, 0) ==
> > win32event.WAIT_TIMEOUT:
> >             self.server.handle_request()
>
> The loop above should keep running until hWaitStop is set, with a maximum  
> wait time (inside handle_request) corresponding to the socket timeout  
> value.
> You can either:
> - use socket.setdefaulttimeout() (in __init__, by example) before anything  
> else. This will set a global timeout for all sockets.
> - modify the socket instance. Just add this method to your AsyncServer:
>      def server_activate(self):
>          SimpleXMLRPCServer.server_activate(self)
>         self.socket.settimeout(15) # for 15 secs
>
> --
> Gabriel Genellina

> >     def SvcDoRun(self):
> >         self.server.register_instance(MyClass())
>
> >         #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?
> For example, see <http://msdn2.microsoft.com/en-us/library/ms681382.aspx>.
> Python 2.5.1 + pywin32 210 prints this on my PC:
> 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.

> - use socket.setdefaulttimeout() (in __init__, by example) before anything  
> else. This will set a global timeout for all sockets.

That was the one that did it.

Thank you again Gabriel.  I'll post back with something complete.

~Sean

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

Reply via email to