This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Documentation for threading.enumerate / threading.Thread.is_alive is contradictory.
Type: Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: anthonygreen, docs@python, iritkatriel, miss-islington, pitrou
Priority: normal Keywords: patch

Created on 2015-12-07 23:58 by anthonygreen, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23192 merged iritkatriel, 2020-11-07 18:38
PR 26035 merged miss-islington, 2021-05-11 17:55
PR 26036 merged miss-islington, 2021-05-11 17:55
Messages (4)
msg256094 - (view) Author: Anthony Green (anthonygreen) Date: 2015-12-08 00:03
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]."
msg256097 - (view) Author: Anthony Green (anthonygreen) Date: 2015-12-08 00:09
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)>]
msg393467 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-05-11 18:19
New changeset 7bef7a180da56e0399f4dec2c992bb101470fc73 by Miss Islington (bot) in branch '3.10':
bpo-25821: Fix inaccuracy in threading.enumerate/is_alive documentation (GH-23192) (#26035)
https://github.com/python/cpython/commit/7bef7a180da56e0399f4dec2c992bb101470fc73
msg393468 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-05-11 18:19
New changeset bde14f7fbd5f11bb40d9c314bd74eaa231236c6b by Miss Islington (bot) in branch '3.9':
bpo-25821: Fix inaccuracy in threading.enumerate/is_alive documentation (GH-23192) (#26036)
https://github.com/python/cpython/commit/bde14f7fbd5f11bb40d9c314bd74eaa231236c6b
History
Date User Action Args
2022-04-11 14:58:24adminsetgithub: 70007
2021-05-11 18:20:25iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-05-11 18:19:50iritkatrielsetmessages: + msg393468
2021-05-11 18:19:44iritkatrielsetmessages: + msg393467
2021-05-11 17:55:37miss-islingtonsetpull_requests: + pull_request24683
2021-05-11 17:55:33miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24682
2021-05-11 17:35:43iritkatrielsetversions: + Python 3.11, - Python 3.8
2020-11-07 18:40:42iritkatrielsetcomponents: + Library (Lib)
versions: + Python 3.8, Python 3.9, Python 3.10, - Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
2020-11-07 18:38:50iritkatrielsetkeywords: + patch
nosy: + iritkatriel

pull_requests: + pull_request22095
stage: patch review
2015-12-08 00:09:37anthonygreensetmessages: + msg256097
2015-12-08 00:03:40anthonygreensetmessages: + msg256094
2015-12-07 23:58:32anthonygreencreate