Commit b0e700d
committed
Fix circular import between threading and _threading_local
Since Python 3.7 thread support is always available, _thread._local
always exists. The fallback 'try: from _thread import _local except
ImportError: from _threading_local import local' is obsolete and
reintroduces a circular import when _thread._local is deleted
(e.g. del _thread._local; import threading).
- In Lib/threading.py, remove the try/except fallback and directly
use 'from _thread import _local as local'.
- In Lib/_threading_local.py, remove the top-level
'from threading import current_thread, RLock' and use lazy imports
inside get_dict(), create_dict(), and local.__new__().
This breaks the cycle and makes 'import _thread; del _thread._local;
import threading' succeed, as reported in the issue.
Fixes #156341
Co-authored-by: Muse Spark <muse-spark@users.noreply.github.com>
Co-authored-by: Aryan Singh K <70511529+aryansk@users.noreply.github.com>
AI disclosure: Muse Spark assisted in analysis and fix drafting;
changes reviewed and tested manually (py_compile ok).
Signed-off-by: aryansk <70511529+aryansk@users.noreply.github.com>1 parent a728080 commit b0e700d
2 files changed
Lines changed: 8 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
| 90 | + | |
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| |||
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
118 | | - | |
119 | | - | |
120 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
71 | 69 | | |
72 | 70 | | |
73 | 71 | | |
| |||
0 commit comments