0

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

Rdd
  • 103
  • 2

1 Answers1

0

As per the docs:

timeout is not a time limit on the entire response download; rather, an exception is raised if the server has not issued a response for timeout seconds (more precisely, if no bytes have been received on the underlying socket for timeout seconds).

In other words, the behavior you're seeing is expected--the timeout will not be triggered so long as the server begins to issue the response before the timeout expires.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Thank you! Do you know if there is any way to have a request time out (or raise another error) after a certain length of time, regardless of whether it's complete? – Rdd Nov 29 '17 at 14:53
  • @RuaraidhDobson: Yes. See the question I've marked this as a duplicate of. – John Zwinck Nov 29 '17 at 14:54
  • Thank you - you're right, that's a big help. Sorry for the duplicate question. – Rdd Nov 29 '17 at 14:56