How to kill a SocketServer?

Jean-Pierre Bergamin james at ractive.ch
Mon Apr 12 16:03:28 EDT 2004


Diez B. Roggisch wrote:

>> The problem is, that I found no way to interrupt the blocking call to
>> self.rfile.readline(). Is there a way to do that?
>
> From the SocketServerDocs:
>
> ---------------
> serve_forever()
>
>  Handle an infinite number of requests. This simply calls
> handle_request() inside an infinite loop.
>
> ---------------
>
> So simply call handle_request yourself, like this:
>
> while self.run_me:
>   s.server_forever()

I'm already having such a construct. The problem is the following:
The server waits for a connection and it calls in
SocketServer.TCPServer.handle_request() the function self.socket.accept().
This call blocks until a connections is made.

I have no chance to interrupt this call. I also tried:

def stop_server:
    self.socket.shutdown(2)
    self.socket.close()
    self.run_me = False

The accept() call still won't get interrupted. :-(

Other ideas?


James

-- 
http://www.p800.info





More information about the Python-list mailing list