Python Glossary Русский

all Python 3until 3.9threadingfunction

threading.Thread.isAlive()

removed

Old name of Thread.is_alive(): whether the thread is still running. Removed in Python 3.9; use is_alive() instead.

Syntax

t.isAlive()  # до 3.9

The camelCase name dates from the first threading versions modelled on Java. Since Python 2.6 the method also has a PEP 8 name, is_alive(); the old one was deprecated in 3.8 and removed in 3.9. How to rewrite: t.isAlive() becomes t.is_alive(). Behaviour is the same: True from start() until run() finishes. Check the neighbouring old names too: getName()/setName() become the t.name attribute, isDaemon()/setDaemon() become t.daemon.

Examples

# Python 3.9+
import threading
t = threading.Thread(target=lambda: None)
try:
    t.isAlive()
except AttributeError as e:
    print(type(e).__name__)  # → AttributeError
# Python 3.9+
import threading
t = threading.Thread(target=lambda: None)
print(t.is_alive())  # → False — ещё не запущен
t.start()
t.join()
print(t.is_alive())  # → False — уже завершился
import threading
t = threading.Thread(target=lambda: None)
t.start()
t.join()
print(t.isAlive())  # → False

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy