Describing is_alive()
- The
is_alivemethod determines if a thread is alive or not - Specifically, it returns
Trueif the tread is alive - And, it returns
Falseotherwise - A thread is alive from the moment the
startmethod returns - A threead is not alive anymore when the
runmethod terminates
Example of is_alive
>>> import logging
>>> from threading import Thread
>>> import time
>>> def sleepy():
... print('thread started')
... time.sleep(10)
... print('thread done')
>>> t = Thread(target=sleepy).start()
'thread started'
>>> t.is_alive()
True
'thread done'
>>> t.is_alive()
FalseReferences
Previous
Next