From 6e94740acbbe8b12a28d8f2ad4ac9dc5fc28e867 Mon Sep 17 00:00:00 2001 From: Robert Brewer Date: Thu, 13 Nov 2025 08:39:29 -0800 Subject: [PATCH 1/3] Fix isAlive/is_alive for various Pythons --- magicbus/plugins/lifecycle.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/magicbus/plugins/lifecycle.py b/magicbus/plugins/lifecycle.py index b744ba55..d048b992 100644 --- a/magicbus/plugins/lifecycle.py +++ b/magicbus/plugins/lifecycle.py @@ -16,6 +16,11 @@ except AttributeError: max_files = 1024 +if hasattr(threading.currentThread(), "is_alive"): + is_alive = lambda t: t.is_alive() +else: + is_alive = lambda t: t.isAlive() + from magicbus import plugins @@ -39,13 +44,17 @@ class ThreadWait(plugins.SimplePlugin): def EXIT(self): # Waiting for ALL child threads to finish is necessary on OS X. - # See https://github.com/cherrypy/cherrypy/issues/581. + # See http://www.cherrypy.org/ticket/581. # It's also good to let them all shut down before allowing # the main thread to call atexit handlers. - # See https://github.com/cherrypy/cherrypy/issues/751. + # See http://www.cherrypy.org/ticket/751. self.bus.log('Waiting for child threads to terminate...') + curthread = threading.currentThread() for t in threading.enumerate(): - if t == threading.current_thread() or not t.is_alive(): + if t is curthread: + continue + + if not is_alive(t): continue # Note that any dummy (external) threads are always daemonic. From 89724241620e77aa43f8e7eb2afd4b6ad7f3d245 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 13 Nov 2025 16:41:09 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- magicbus/plugins/lifecycle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/magicbus/plugins/lifecycle.py b/magicbus/plugins/lifecycle.py index d048b992..a4960bae 100644 --- a/magicbus/plugins/lifecycle.py +++ b/magicbus/plugins/lifecycle.py @@ -16,7 +16,7 @@ except AttributeError: max_files = 1024 -if hasattr(threading.currentThread(), "is_alive"): +if hasattr(threading.currentThread(), 'is_alive'): is_alive = lambda t: t.is_alive() else: is_alive = lambda t: t.isAlive() From d812086a4a6407604c63445b619d9bee7fa64199 Mon Sep 17 00:00:00 2001 From: Robert Brewer Date: Thu, 13 Nov 2025 09:03:57 -0800 Subject: [PATCH 3/3] oops --- magicbus/plugins/lifecycle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magicbus/plugins/lifecycle.py b/magicbus/plugins/lifecycle.py index a4960bae..1ada3ba0 100644 --- a/magicbus/plugins/lifecycle.py +++ b/magicbus/plugins/lifecycle.py @@ -44,10 +44,10 @@ class ThreadWait(plugins.SimplePlugin): def EXIT(self): # Waiting for ALL child threads to finish is necessary on OS X. - # See http://www.cherrypy.org/ticket/581. + # See https://github.com/cherrypy/cherrypy/issues/581. # It's also good to let them all shut down before allowing # the main thread to call atexit handlers. - # See http://www.cherrypy.org/ticket/751. + # See https://github.com/cherrypy/cherrypy/issues/751. self.bus.log('Waiting for child threads to terminate...') curthread = threading.currentThread() for t in threading.enumerate():