Normalize thread names

Every thread now has a name and either a contextually relevant
identifier or their in hex to disambiguate multiple threads of the same
type.  Also finally gets rid of that old python 2 style init call.
This commit is contained in:
Imayhaveborkedit
2023-09-03 02:41:16 -04:00
committed by GitHub
parent e414d0fe04
commit 7bdfd454be
2 changed files with 8 additions and 7 deletions

View File

@ -132,11 +132,12 @@ class KeepAliveHandler(threading.Thread):
shard_id: Optional[int] = None,
**kwargs: Any,
) -> None:
super().__init__(*args, **kwargs)
daemon: bool = kwargs.pop('daemon', True)
name: str = kwargs.pop('name', f'keep-alive-handler:shard-{shard_id}')
super().__init__(*args, daemon=daemon, name=name, **kwargs)
self.ws: DiscordWebSocket = ws
self._main_thread_id: int = ws.thread_id
self.interval: Optional[float] = interval
self.daemon: bool = True
self.shard_id: Optional[int] = shard_id
self.msg: str = 'Keeping shard ID %s websocket alive with sequence %s.'
self.block_msg: str = 'Shard ID %s heartbeat blocked for more than %s seconds.'
@ -212,7 +213,8 @@ class KeepAliveHandler(threading.Thread):
class VoiceKeepAliveHandler(KeepAliveHandler):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
name: str = kwargs.pop('name', f'voice-keep-alive-handler:{id(self):#x}')
super().__init__(*args, name=name, **kwargs)
self.recent_ack_latencies: Deque[float] = deque(maxlen=20)
self.msg: str = 'Keeping shard ID %s voice websocket alive with timestamp %s.'
self.block_msg: str = 'Shard ID %s voice heartbeat blocked for more than %s seconds'