I'm using a Raspberry Pi 3 with Raspbian 8 (Jessie) to post data to a server using a cell connection, which can be unreliable. I have had a tricky bug where the thread sending the data hangs but does not time out, and so data posting pauses entirely for long periods of time with no logging or such.
I've replicated this by artificially slowing the Pi's connection significantly (using tc/netem to add about 20 seconds of latency). When doing this, the request will hang for much longer than the timeout period. I assume (but don't know for sure) that this is because a very few packets make it through on the slow connection. Is there a way to raise an error if this happens? Or is my assumption wrong?
Request code:
result = requests.post(target_url, json=data_dict, timeout=5)
Thanks