title: How to flush/clear buffer in a socket in python3
body: <p>How do I flush a socket in python3?</p>
  
  <p>I'm looking to do something like this</p>
  
  <pre><code>def clear_buffer(sock):
      try:
          while sock.recv(1024): pass
      except:
          pass
  </code></pre>
  
  <p>or</p>
  
  <pre><code>def clear_buffer(sock):
      while True:
          data = sock.recv(1024)
          if not data:
              break
  </code></pre>
  
  <p>After attempting to run these two functions neither seem to break the while loop and/or flush out the socket from incoming data. How do I conditionally do something when the socket has stopped receiving data?</p>