From 1022b07e0e2cd6f34d62626d8ad361a07acd89db Mon Sep 17 00:00:00 2001 From: TheSpookyCat <24483290+TheSpookyCat@users.noreply.github.com> Date: Thu, 25 May 2023 17:39:17 +0100 Subject: [PATCH] - Introduce `connection_timeout` and `response_timeout` kwargs - - Loosely based on #195 - Calls `get_ipc_path()` each time a handshake is begun - - (Windows) DiscordNotFound will no longer be raised on object initialization, instead raises on handshake - `InvalidID` is no longer raised when the pipe is closed for any reason. `PipeClosed` is now raised instead --- pypresence/baseclient.py | 46 +++++++++++++++++++++++----------------- pypresence/exceptions.py | 29 +++++++++++++++++++------ 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/pypresence/baseclient.py b/pypresence/baseclient.py index ac3fae7..78e7d11 100644 --- a/pypresence/baseclient.py +++ b/pypresence/baseclient.py @@ -16,16 +16,14 @@ class BaseClient: def __init__(self, client_id: str, **kwargs): - pipe = kwargs.get('pipe', None) loop = kwargs.get('loop', None) handler = kwargs.get('handler', None) + self.pipe = kwargs.get('pipe', None) self.isasync = kwargs.get('isasync', False) + self.connection_timeout = kwargs.get('connection_timeout', 30) + self.response_timeout = kwargs.get('response_timeout', 10) client_id = str(client_id) - self.ipc_path = get_ipc_path(pipe) - - if not self.ipc_path: - raise DiscordNotFound if loop is not None: self.update_event_loop(loop) @@ -78,11 +76,13 @@ async def _async_err_handle(self, loop, context: dict): async def read_output(self): try: - preamble = await self.sock_reader.read(8) + preamble = await asyncio.wait_for(self.sock_reader.read(8), self.response_timeout) status_code, length = struct.unpack('