interrupt - Python: Stop the socket-receiving-process -
i receive data device via socket-module. after time device stops sending packages. want interupt for-loop. while true doesn't work, because receives more 100 packages. how can stop process? s stands socket.
... in range(packages100): data = s.recv(4) f.write(data) ...
edit: think socket.settimeout() part of solution. see also: how set timeout on python's socket recv method?
if peer stops sending data, opposed closing connection, tricky , you'll forced resort asynchronous reading socket.
put in asynchronous mode (the docs , google friends), , try read each time, instead of blocking read. can stop "trying" anytime wish. note nature of async io code bit different - no longer able assume once recv
returns, read data.
Comments
Post a Comment