I have a service that uses a blocking socket to receive data. The problem is that I donβt know how to close the socket correctly if it is still waiting for data. The following is a brief excerpt from how I open and wait for data: I do not want to use timeouts, because according to the python documentation, the socket must be blocked in order to use makefile .
Maybe I'm wrong, as I'm new to socket programming.
EDIT:
It should be noted that I cannot change the way the server works.
import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) reader = s.makefile("rb") line = reader.readline()
source share