diff options
| author | Rapptz <[email protected]> | 2017-08-19 22:15:29 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-08-19 22:15:29 -0400 |
| commit | deaba1f5ab530966ca50e13eb2c89623a1b7527b (patch) | |
| tree | c4ec5b7037bee4fd21c22881440859bb53d15098 | |
| parent | Consume remaining keyword arguments in Game constructor. (diff) | |
| download | discord.py-deaba1f5ab530966ca50e13eb2c89623a1b7527b.tar.xz discord.py-deaba1f5ab530966ca50e13eb2c89623a1b7527b.zip | |
Use time.monotonic instead of time.time for heartbeat code.
| -rw-r--r-- | discord/gateway.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/discord/gateway.py b/discord/gateway.py index e3825d26..0ab02760 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -62,13 +62,13 @@ class KeepAliveHandler(threading.Thread): self.shard_id = shard_id self.msg = 'Keeping websocket alive with sequence %s.' self._stop_ev = threading.Event() - self._last_ack = time.time() - self._last_send = time.time() + self._last_ack = time.monotonic() + self._last_send = time.monotonic() self.heartbeat_timeout = ws._max_heartbeat_timeout def run(self): while not self._stop_ev.wait(self.interval): - if self._last_ack + self.heartbeat_timeout < time.time(): + if self._last_ack + self.heartbeat_timeout < time.monotonic(): log.warn("Shard ID %s has stopped responding to the gateway. Closing and restarting." % self.shard_id) coro = self.ws.close(1006) f = compat.run_coroutine_threadsafe(coro, loop=self.ws.loop) @@ -91,7 +91,7 @@ class KeepAliveHandler(threading.Thread): except Exception: self.stop() else: - self._last_send = time.time() + self._last_send = time.monotonic() def get_payload(self): return { @@ -103,7 +103,7 @@ class KeepAliveHandler(threading.Thread): self._stop_ev.set() def ack(self): - self._last_ack = time.time() + self._last_ack = time.monotonic() class VoiceKeepAliveHandler(KeepAliveHandler): def __init__(self, *args, **kwargs): |