diff options
| author | Rapptz <[email protected]> | 2020-04-14 04:21:20 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-04-14 04:21:20 -0400 |
| commit | d6be6adf8b1193b83ac23b941fbf5336ca5f4208 (patch) | |
| tree | 1441a77b1e5213588b5b52be111aeb34b64823d8 | |
| parent | Remove from the FAQ that there's no event for invites being created (diff) | |
| download | discord.py-d6be6adf8b1193b83ac23b941fbf5336ca5f4208.tar.xz discord.py-d6be6adf8b1193b83ac23b941fbf5336ca5f4208.zip | |
Add traceback to debug blocking issues
| -rw-r--r-- | discord/gateway.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/discord/gateway.py b/discord/gateway.py index 439cdfa8..7de75cb7 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -33,6 +33,7 @@ import struct import sys import time import threading +import traceback import zlib import websockets @@ -66,6 +67,7 @@ class KeepAliveHandler(threading.Thread): shard_id = kwargs.pop('shard_id', None) threading.Thread.__init__(self, *args, **kwargs) self.ws = ws + self._main_thread_id = ws.thread_id self.interval = interval self.daemon = True self.shard_id = shard_id @@ -106,7 +108,14 @@ class KeepAliveHandler(threading.Thread): break except concurrent.futures.TimeoutError: total += 5 - log.warning(self.block_msg, total) + try: + frame = sys._current_frames()[self._main_thread_id] + except KeyError: + msg = self.block_msg + else: + stack = traceback.format_stack(frame) + msg = '%s\nLoop thread stacktrace:\n%s' % (self.block_msg, ''.join(stack)) + log.warning(msg, total) except Exception: self.stop() @@ -215,6 +224,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): self._dispatch_listeners = [] # the keep alive self._keep_alive = None + self.thread_id = threading.get_ident() # ws related stuff self.session_id = None @@ -648,6 +658,7 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol): ws.gateway = gateway ws._connection = client ws._max_heartbeat_timeout = 60.0 + ws.thread_id = threading.get_ident() if resume: await ws.resume() |