praw-dev/praw — pull request #341 by lfairy (2014-11-02 05:47:29+00:00)
Title: Use monotonic clocks for rate limiting

This patch changes every occurrence of `time.time()` to `timeit.default_timer()`.

Currently, the rate limiter uses `time.time()` for getting the current time. Unfortunately, [`time.time()` is not monotonic][1]. If the system clock is adjusted while `praw` is running, it can lead to the rate limiter waiting too long or not at all.

A better alternative is [`timeit.default_timer()`][2]. Since Python 3.3, this function is monotonic. Older versions alias to `time.time()`, which is no different to what we have now. It's been in the standard library since Python 2.3 (albeit not documented) so there should be no issues with compatibility.

[1]: https://docs.python.org/3/library/time.html#time.time
[2]: https://docs.python.org/3/library/timeit.html#timeit.default_timer