mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-11 16:29:49 +00:00
Add traceback to debug blocking issues
This commit is contained in:
parent
0cef8c1f60
commit
d6be6adf8b
@ -33,6 +33,7 @@ import struct
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
import traceback
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
@ -66,6 +67,7 @@ class KeepAliveHandler(threading.Thread):
|
|||||||
shard_id = kwargs.pop('shard_id', None)
|
shard_id = kwargs.pop('shard_id', None)
|
||||||
threading.Thread.__init__(self, *args, **kwargs)
|
threading.Thread.__init__(self, *args, **kwargs)
|
||||||
self.ws = ws
|
self.ws = ws
|
||||||
|
self._main_thread_id = ws.thread_id
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.shard_id = shard_id
|
self.shard_id = shard_id
|
||||||
@ -106,7 +108,14 @@ class KeepAliveHandler(threading.Thread):
|
|||||||
break
|
break
|
||||||
except concurrent.futures.TimeoutError:
|
except concurrent.futures.TimeoutError:
|
||||||
total += 5
|
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:
|
except Exception:
|
||||||
self.stop()
|
self.stop()
|
||||||
@ -215,6 +224,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
self._dispatch_listeners = []
|
self._dispatch_listeners = []
|
||||||
# the keep alive
|
# the keep alive
|
||||||
self._keep_alive = None
|
self._keep_alive = None
|
||||||
|
self.thread_id = threading.get_ident()
|
||||||
|
|
||||||
# ws related stuff
|
# ws related stuff
|
||||||
self.session_id = None
|
self.session_id = None
|
||||||
@ -648,6 +658,7 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
ws.gateway = gateway
|
ws.gateway = gateway
|
||||||
ws._connection = client
|
ws._connection = client
|
||||||
ws._max_heartbeat_timeout = 60.0
|
ws._max_heartbeat_timeout = 60.0
|
||||||
|
ws.thread_id = threading.get_ident()
|
||||||
|
|
||||||
if resume:
|
if resume:
|
||||||
await ws.resume()
|
await ws.resume()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user