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: current_thread() becomes "dummy" thread during shutdown
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, miss-islington, pitrou, serhiy.storchaka, tim.peters, vstinner
Priority: normal Keywords: patch

Created on 2017-09-19 11:33 by pitrou, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mainthread.py pitrou, 2017-09-19 11:33
Pull Requests
URL Status Linked Edit
PR 3673 merged pitrou, 2017-09-20 16:43
PR 3856 merged python-dev, 2017-10-02 14:42
PR 8052 merged ZackerySpytz, 2018-07-02 20:10
PR 9813 merged miss-islington, 2018-10-12 08:31
PR 9814 merged miss-islington, 2018-10-12 08:31
Messages (10)
msg302515 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-09-19 11:33
Attaching reproducer.  During interpreter shutdown, threading.main_thread() gets marked "stopped" (while it's obviously still running), while threading.current_thread() returns a DummyThread instance with the same ident as the main thread.

$ ./python mainthread.py 
-- before shutdown --
GC in thread <_MainThread(MainThread, started 140359122872064)>
main thread is <_MainThread(MainThread, started 140359122872064)>
-- during shutdown --
GC in thread <_DummyThread(Dummy-1, started daemon 140359122872064)>
main thread is <_MainThread(MainThread, stopped 140359122872064)>
msg302517 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-09-19 11:47
The main thread being marked "stopped" at shutdown might be an obscure feature (as hinted in the comments for threading._shutdown()).  However, current_thread() should definitely not return a separate DummyThread instance.
msg302637 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-09-20 17:00
Tim, any opinion on this one?  Do you agree it's an actual bug (if a bit obscure)?
msg302641 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2017-09-20 17:21
Ya, it's clearly best for `current_thread()` to deliver consistent results.
msg303537 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-10-02 14:42
New changeset 1023dbbcb7f05e76053486ae7ef7f73b4cdc5398 by Antoine Pitrou in branch 'master':
bpo-31516: current_thread() should not return a dummy thread at shutdown (#3673)
https://github.com/python/cpython/commit/1023dbbcb7f05e76053486ae7ef7f73b4cdc5398
msg303542 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-10-02 15:20
New changeset ac6245a31f9a757db0520722c592cb7fdcb55eb0 by Antoine Pitrou (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-31516: current_thread() should not return a dummy thread at shutdown (GH-3673) (#3856)
https://github.com/python/cpython/commit/ac6245a31f9a757db0520722c592cb7fdcb55eb0
msg303543 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-10-02 15:20
I have now pushed the fix to master and 3.6.  Hopefully this won't break anyone's code...
msg327572 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-12 08:31
New changeset 65d2f8c044bf597685ba72f66cbcc6b3f7a3ee9c by Serhiy Storchaka (Zackery Spytz) in branch 'master':
bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds. (GH-8052)
https://github.com/python/cpython/commit/65d2f8c044bf597685ba72f66cbcc6b3f7a3ee9c
msg327573 - (view) Author: miss-islington (miss-islington) Date: 2018-10-12 08:49
New changeset c327a5499fa823f627366c17e20687065fd70449 by Miss Islington (bot) in branch '3.7':
bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds. (GH-8052)
https://github.com/python/cpython/commit/c327a5499fa823f627366c17e20687065fd70449
msg327575 - (view) Author: miss-islington (miss-islington) Date: 2018-10-12 08:54
New changeset d918e98056b7ef8d90d71805531cec3e67b5450e by Miss Islington (bot) in branch '3.6':
bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds. (GH-8052)
https://github.com/python/cpython/commit/d918e98056b7ef8d90d71805531cec3e67b5450e
History
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75697
2018-10-12 08:54:24miss-islingtonsetmessages: + msg327575
2018-10-12 08:49:12miss-islingtonsetnosy: + miss-islington
messages: + msg327573
2018-10-12 08:31:40miss-islingtonsetpull_requests: + pull_request9192
2018-10-12 08:31:34miss-islingtonsetpull_requests: + pull_request9191
2018-10-12 08:31:28serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg327572
2018-07-02 20:10:56ZackerySpytzsetpull_requests: + pull_request7660
2017-10-02 15:20:39pitrousetstatus: open -> closed
resolution: fixed
messages: + msg303543

stage: patch review -> resolved
2017-10-02 15:20:04pitrousetmessages: + msg303542
2017-10-02 14:42:32python-devsetpull_requests: + pull_request3836
2017-10-02 14:42:17pitrousetmessages: + msg303537
2017-09-20 17:21:03tim.peterssetmessages: + msg302641
2017-09-20 17:00:04pitrousetmessages: + msg302637
2017-09-20 16:43:35pitrousetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request3662
2017-09-19 20:55:32vstinnersetnosy: + vstinner
2017-09-19 11:47:18pitrousetmessages: + msg302517
2017-09-19 11:33:54pitroucreate