Re: BaseHTTPServer get_request not called till first request

2010-01-17 Thread Adam Tauno Williams
On Sat, 2010-01-16 at 18:35 -0800, yousay wrote:
> On Jan 13, 1:38 am, Adam Tauno Williams 
> wrote:
> > Looking at  and
> >  as examples I've attempted
> > to create a BaseHTTPServer class that times-out accept() ever X seconds
> > to check some other work.  This seems to work well, but only once the
> > HTTPServer object has received its first request.  Up until the first
> > request get_request() is not invoked and not timeout occurs.
> > class HTTPServer(BaseHTTPServer.HTTPServer):
> > def server_bind(self):
> > BaseHTTPServer.HTTPServer.server_bind(self)
> > self.socket.settimeout(1)
> > self._shutdown = False
> > def get_request(self):
> > while not self._shutdown:
> > try:
> > print ' HTTP worker {0} waiting.'.format(self.pid)
> > self.log.debug('Waiting for connection...')
> > s, a = self.socket.accept()
> > s.settimeout(None)
> > return (s, a)
> > except socket.timeout:
> > /// do other work ///
> > return None, None
> > The "HTTP worker" message is not seen until the server has taken a
> > request, then it seems to dutifully do the timeout.
> your class Name is the same to the superClass,may be have influence

Nope, changed the name of the class (cleaned out all the *.pyc files),
and the initial wait still does not time out.


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


Re: BaseHTTPServer get_request not called till first request

2010-01-16 Thread yousay
On Jan 13, 1:38 am, Adam Tauno Williams 
wrote:
> Looking at  and
>  as examples I've attempted
> to create a BaseHTTPServer class that times-out accept() ever X seconds
> to check some other work.  This seems to work well, but only once the
> HTTPServer object has received its first request.  Up until the first
> request get_request() is not invoked and not timeout occurs.
>
> class HTTPServer(BaseHTTPServer.HTTPServer):
>
>     def server_bind(self):
>         BaseHTTPServer.HTTPServer.server_bind(self)
>         self.socket.settimeout(1)
>         self._shutdown = False
>
>     def get_request(self):
>         while not self._shutdown:
>             try:
>                 print ' HTTP worker {0} waiting.'.format(self.pid)
>                 self.log.debug('Waiting for connection...')
>                 s, a = self.socket.accept()
>                 s.settimeout(None)
>                 return (s, a)
>             except socket.timeout:
>                 /// do other work ///
>         return None, None
>
> The "HTTP worker" message is not seen until the server has taken a
> request, then it seems to dutifully do the timeout.
>
> --
> OpenGroupware developer: awill...@whitemice.org
> 
> OpenGroupare & Cyrus IMAPd documenation @
> 

your class Name is the same to the superClass,may be have influence
-- 
http://mail.python.org/mailman/listinfo/python-list


BaseHTTPServer get_request not called till first request

2010-01-12 Thread Adam Tauno Williams
Looking at  and
 as examples I've attempted
to create a BaseHTTPServer class that times-out accept() ever X seconds
to check some other work.  This seems to work well, but only once the
HTTPServer object has received its first request.  Up until the first
request get_request() is not invoked and not timeout occurs.

class HTTPServer(BaseHTTPServer.HTTPServer):

def server_bind(self):
BaseHTTPServer.HTTPServer.server_bind(self)
self.socket.settimeout(1)
self._shutdown = False

def get_request(self):
while not self._shutdown:
try:
print ' HTTP worker {0} waiting.'.format(self.pid)
self.log.debug('Waiting for connection...')
s, a = self.socket.accept()
s.settimeout(None)
return (s, a)
except socket.timeout:
/// do other work ///
return None, None

The "HTTP worker" message is not seen until the server has taken a
request, then it seems to dutifully do the timeout.

-- 
OpenGroupware developer: awill...@whitemice.org

OpenGroupare & Cyrus IMAPd documenation @


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