title: Python: Stop the socket-receiving-process
body: <p>I receive data from some device via socket-module.
  But after some time the device stops sending packages.
  Then I want to interupt the for-loop.
  While True doesn't work, because he receives more then 100 packages.
  How can I stop this process?
  s stands for socket.</p>
  <pre><code>...
  for i in range(packages100):
      data = s.recv(4)
      f.write(data)
  ...
  </code></pre>
  <p>Edit:
  I think socket.settimeout() is part of the solution. See also:
  <a href="https://stackoverflow.com/questions/2719017/how-to-set-timeout-on-pythons-socket-recv-method">How to set timeout on python&#39;s socket recv method?</a></p>