diff --git a/python/helpers/pydev/_pydev_bundle/pydev_is_thread_alive.py b/python/helpers/pydev/_pydev_bundle/pydev_is_thread_alive.py index a40343ee33e1..11ba770558fa 100644 --- a/python/helpers/pydev/_pydev_bundle/pydev_is_thread_alive.py +++ b/python/helpers/pydev/_pydev_bundle/pydev_is_thread_alive.py @@ -1,20 +1,28 @@ from _pydev_imps._pydev_saved_modules import threading -# Hack for https://www.brainwy.com/tracker/PyDev/363 (i.e.: calling isAlive() can throw AssertionError under some -# circumstances). +# Hack for https://www.brainwy.com/tracker/PyDev/363 +# I.e.: calling isAlive() can throw AssertionError under some circumstances # It is required to debug threads started by start_new_thread in Python 3.4 _temp = threading.Thread() -if hasattr(_temp, '_is_stopped'): # Python 3.x has this + +# Python <=3.12 +if hasattr(_temp, '_is_stopped'): def is_thread_alive(t): return not t._is_stopped -elif hasattr(_temp, '_Thread__stopped'): # Python 2.x has this +# Python 2.x +elif hasattr(_temp, '_Thread__stopped'): def is_thread_alive(t): return not t._Thread__stopped -else: - # Jython wraps a native java thread and thus only obeys the public API. +# Jython wraps a native java thread and thus only obeys the public API +elif hasattr(_temp, 'isAlive'): def is_thread_alive(t): return t.isAlive() +# Python >=3.13 +else: + def is_thread_alive(t): + return t.is_alive() + del _temp