FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix circular import between threading and _threading_local by aryansk · Pull Request #156357 · python/cpython · GitHub

/ cpython Public
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions Lib/_threading_local.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ def __init__(self):
def get_dict(self):
"""Return the dict for the current thread. Raises KeyError if none
defined."""
from threading import current_thread
thread = current_thread()
return self.dicts[id(thread)][1]

def create_dict(self):
"""Create a new dict for the current thread, and return it."""
from threading import current_thread
localdict = {}
key = self.key
thread = current_thread()
Expand Down Expand Up @@ -85,6 +87,7 @@ class local:
def __new__(cls, /, *args, **kw):
if (args or kw) and (cls.__init__ is object.__init__):
raise TypeError("Initialization arguments are not supported")
from threading import RLock
self = object.__new__(cls)
impl = _localimpl()
impl.localargs = (args, kw)
Expand Down Expand Up @@ -115,6 +118,3 @@ def __delattr__(self, name):
% self.__class__.__name__)
with _patch(self):
return object.__delattr__(self, name)


from threading import current_thread, RLock
12 changes: 5 additions & 7 deletions Lib/threading.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@
TIMEOUT_MAX = _thread.TIMEOUT_MAX
del _thread

# get thread-local implementation, either from the thread
# module, or from the python fallback

try:
from _thread import _local as local
except ImportError:
from _threading_local import local
# get thread-local implementation from the thread module
# (fallback to _threading_local is obsolete since Python 3.7 - thread support
# is always available, and _thread._local always exists; keeping the fallback
# would reintroduce the circular import with _threading_local)
from _thread import _local as local

# Support for profile and trace hooks

Expand Down
Loading

Back | FazBrowse Home | New Git URL