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

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -