From: Christian Heller Date: Thu, 2 Oct 2025 18:28:14 +0000 (+0200) Subject: From Client.connect thread, move anything not measurably blocking UI back into main... X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=add32343e9ba7d49615ae3b3b343fb2006f220a0;p=ircplom From Client.connect thread, move anything not measurably blocking UI back into main thread. --- diff --git a/src/ircplom/client.py b/src/ircplom/client.py index 2714ccc..619d554 100644 --- a/src/ircplom/client.py +++ b/src/ircplom/client.py @@ -850,25 +850,30 @@ class Client(ABC, ClientQueueMixin): hostname=self.db.hostname, port=self.db.port, _q_out=self._q_out, client_id=self.client_id) except IrcConnException as e: - self.db.connection_state = f'failed to connect: {e}' - if isinstance(e, IrcConnTimeoutException): - if not self._retry_connect_in_s > 0: - self._retry_connect_in_s = 1 - self._client_trigger('_delayed_retry_connect') + self._client_trigger('_on_connecting_exception', e=e) except Exception as e: # pylint: disable=broad-exception-caught self._put(ExceptionEvent(CrashingException(e))) else: - self._expected_pong = '' - self._retry_connect_in_s = -1 - self.db.connection_state = 'connected' - self.caps.start_negotation() - self.send('USER', self.db.user_wanted, - '0', '*', self.db.realname) - self.send('NICK', self.db.nick_wanted,) + self._client_trigger('_on_connected') # Do this in a thread, not to block flow of other (e.g. TUI) events. Thread(target=connect, daemon=True, args=(self,)).start() + def _on_connecting_exception(self, e: IrcConnException) -> None: + self.db.connection_state = f'failed to connect: {e}' + if isinstance(e, IrcConnTimeoutException): + if not self._retry_connect_in_s > 0: + self._retry_connect_in_s = 1 + self._delayed_retry_connect() + + def _on_connected(self) -> None: + self._expected_pong = '' + self._retry_connect_in_s = -1 + self.db.connection_state = 'connected' + self.caps.start_negotation() + self.send('USER', self.db.user_wanted, '0', '*', self.db.realname) + self.send('NICK', self.db.nick_wanted,) + def _delayed_retry_connect(self) -> None: def delayed_connect(self, wait_s: int, retry_connect_id: UUID ) -> None: