diff --git a/discord/gateway.py b/discord/gateway.py index e3825d26d..0ab027603 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):