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.
...
for i in range(packages100):
data = s.recv(4)
f.write(data)
...
Edit: I think socket.settimeout() is part of the solution. See also: How to set timeout on python's socket recv method?