PY-73047 Use Thread.is_alive instead of Thread._is_stopped in Python 3.13

`Thread._is_stopped` was removed in https://github.com/python/cpython/pull/114839 in Python 3.13

(cherry picked from commit d568bc288aed00268ffeef137b9b901f480964ef)

IJ-MR-137093

GitOrigin-RevId: aa8b27b09db85f69b44d6fbbd333f8ec32489d33
This commit is contained in:
Pavel Karateev
2024-06-18 11:47:27 +02:00
committed by intellij-monorepo-bot
parent 08d43a1e71
commit 2efd9fd5e2

View File

@@ -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