From 11e5d8fbae8fdfa223c450019a63ff77965806eb Mon Sep 17 00:00:00 2001 From: botbikamordehai2-sketch Date: Thu, 28 May 2026 07:54:17 +0000 Subject: [PATCH] fix: reduce CPU spin in run_forever by increasing join timeout (closes #142) --- ws4py/client/threadedclient.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ws4py/client/threadedclient.py b/ws4py/client/threadedclient.py index b033f32..bd0582a 100644 --- a/ws4py/client/threadedclient.py +++ b/ws4py/client/threadedclient.py @@ -54,9 +54,19 @@ def run_forever(self): """ Simply blocks the thread until the websocket has terminated. + + .. note:: + + Signals and threads do not always play well together in Python. + Without a timeout, this method cannot be interrupted by a + SIGINT (KeyboardInterrupt). The timeout ensures we return to + the main thread periodically so pending signals can be + processed. A longer timeout reduces CPU usage in idle + processes at the cost of slightly slower signal response. + Override this method if you need different behaviour. """ while not self.terminated: - self._th.join(timeout=0.1) + self._th.join(timeout=5.0) def handshake_ok(self): """