net4people / bbs

Forum for discussing Internet censorship circumvention
3.2k stars 75 forks source link

Fix reset_seconds #267

Closed tomac4t closed 11 months ago

tomac4t commented 11 months ago

Local time isn't the same as server time, which may cause sleep negative seconds. When it happens, consider retrying after 5 seconds.

wkrp commented 11 months ago

Good find. I thought that a negative duration would cause time.sleep to return immediately, but it looks like it throws an exception instead.

  1. Instead of an if/else, use something like max(reset_seconds, 5).
  2. Use a named variable (up near the top like BASE_URL) instead of the literal 5.
  3. Compute the number of seconds to sleep before the print that shows when the program will resume. Make the displayed timestamp match what was computed (i.e., store datetime.datetime.utcnow() in a variable before computing reset_seconds, then add reset_seconds to it when the timestamp is printed).
wkrp commented 11 months ago

Thanks, that's a pretty nice idea.