mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
Use time.monotonic instead of time.time for heartbeat code.
This commit is contained in:
parent
1c60f9ccf4
commit
deaba1f5ab
@ -62,13 +62,13 @@ class KeepAliveHandler(threading.Thread):
|
|||||||
self.shard_id = shard_id
|
self.shard_id = shard_id
|
||||||
self.msg = 'Keeping websocket alive with sequence %s.'
|
self.msg = 'Keeping websocket alive with sequence %s.'
|
||||||
self._stop_ev = threading.Event()
|
self._stop_ev = threading.Event()
|
||||||
self._last_ack = time.time()
|
self._last_ack = time.monotonic()
|
||||||
self._last_send = time.time()
|
self._last_send = time.monotonic()
|
||||||
self.heartbeat_timeout = ws._max_heartbeat_timeout
|
self.heartbeat_timeout = ws._max_heartbeat_timeout
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while not self._stop_ev.wait(self.interval):
|
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)
|
log.warn("Shard ID %s has stopped responding to the gateway. Closing and restarting." % self.shard_id)
|
||||||
coro = self.ws.close(1006)
|
coro = self.ws.close(1006)
|
||||||
f = compat.run_coroutine_threadsafe(coro, loop=self.ws.loop)
|
f = compat.run_coroutine_threadsafe(coro, loop=self.ws.loop)
|
||||||
@ -91,7 +91,7 @@ class KeepAliveHandler(threading.Thread):
|
|||||||
except Exception:
|
except Exception:
|
||||||
self.stop()
|
self.stop()
|
||||||
else:
|
else:
|
||||||
self._last_send = time.time()
|
self._last_send = time.monotonic()
|
||||||
|
|
||||||
def get_payload(self):
|
def get_payload(self):
|
||||||
return {
|
return {
|
||||||
@ -103,7 +103,7 @@ class KeepAliveHandler(threading.Thread):
|
|||||||
self._stop_ev.set()
|
self._stop_ev.set()
|
||||||
|
|
||||||
def ack(self):
|
def ack(self):
|
||||||
self._last_ack = time.time()
|
self._last_ack = time.monotonic()
|
||||||
|
|
||||||
class VoiceKeepAliveHandler(KeepAliveHandler):
|
class VoiceKeepAliveHandler(KeepAliveHandler):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user