Don't try to solve it with checking everything before.
Work with timeouts. Set the timeout to your socket, then it will throw a socket.timeout exception if you try to read a file and the read took longer than the timeout.
I hope this is a better answer.
By the way, how do you check if a socket is still connected?
I think there is no safe method.
Work with timeouts. Set the timeout to your socket, then it will throw a socket.timeout exception if you try to read a file and the read took longer than the timeout.
import socket def read(fd): try: fd.read(1) except socket.timeout: print("Read timed out") s = socket.socket() s.settimeout(10) # 10 seconds s.connect(("google.com", 80)) f = s.makefile() # will fail read(f)Regular files won't throw a socket.timeout.
I hope this is a better answer.
By the way, how do you check if a socket is still connected?
I think there is no safe method.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!