I am retrieving data from a server using data = sock.recv(buffer_size). There are currently issues being experienced with the server (which I have no control over) resulting in occasional long wait times before receiving a response.
The response is usually almost instant resulting in me receiving the required data. However lately due to the server issue whenever there is a long wait time, I ultimately receive an error message back from the server. When that happens, I have to resend the same request.
My problem is that the sock.recv() call waits too long. What I need to do is only wait for data for a few seconds and if nothing is received I will resend the data request.
So my question is, can I somehow limit the amount of time sock.recv() waits for data? I do not want to kill the connection if I don't receive data in the specified time frame, I just want to know that the time limit has been reached so that I can do something else.