title: Is there anyway to detect a client disconnect in Python SocketServer.TCPServer?
body: <p>I've tried the below code without success. Basically, I need a way to detect the client disconnection. I'd like to avoid a chatty heartbeat type system. Is there anyway to detect when the socket is no longer open (either client has disconnected or it's been broken/etc)?</p>
  
  <pre><code>class ThreadedTCPRequestHandler(SocketServer.StreamRequestHandler):
      def handle(self):
          while True:
              self.data = self.rfile.readline().strip()
              if not self.data:
                  print 'Client closed connection'
                  break
  </code></pre>
  
  <p>I thought this would work, but it doesn't seem to (also tried with the strip() removed). Anyone have any ideas?</p>