[issue25821] Documentation for threading.enumerate / threading.Thread.is_alive is contradictory.
New submission from Anthony Green: The documentation at https://docs.python.org/3/library/threading.html#threading.Thread.is_alive relates:
The module function enumerate() returns a list of all alive threads.
The documentation at https://docs.python.org/3/library/threading.html#threading.enumerate relates:
Return a list of all Thread objects currently alive. The list includes daemonic threads, dummy thread objects created by current_thread(), and the main thread.
This is a contradiction, since if the main thread has stopped, is_alive(main_thread) will return False, but it will still be included in the list returned by threading.enumerate. Note that this is not a TOCTTOU issue. The issue is that enumerate actually includes "all alive threads, plus one [or more? I can't tell from the code] other[s]." ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25821> _______________________________________
Anthony Green added the comment: The following example comes from IRC user ztane:
import threading, time
main_thread = threading.current_thread()
def foo(): time.sleep(10) print(main_thread.is_alive()) print(list(threading.enumerate()))
t = threading.Thread(target=foo) t.start()
False [<_MainThread(MainThread, stopped 140040101766976)>, <Thread(Thread-1, started 140040068695808)>] ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25821> _______________________________________
Change by Irit Katriel <iritkatriel@yahoo.com>: ---------- keywords: +patch nosy: +iritkatriel nosy_count: 3.0 -> 4.0 pull_requests: +22095 stage: -> patch review pull_request: https://github.com/python/cpython/pull/23192 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25821> _______________________________________
Change by Irit Katriel <iritkatriel@yahoo.com>: ---------- components: +Library (Lib) versions: +Python 3.10, Python 3.8, Python 3.9 -Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25821> _______________________________________
participants (2)
-
Anthony Green
-
Irit Katriel