Skip to content

Commit 903178d

Browse files
author
mongkok
committed
Removed current_thread in favor of get_ident
1 parent ee34a06 commit 903178d

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

debug_toolbar/panels/logging.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ def __init__(self) -> None:
2222
"threading module is not available, "
2323
"this panel cannot be used without it"
2424
)
25-
self.collections: t.Dict[t.Any, t.List[t.Dict[str, t.Any]]] = {}
25+
self.collections: t.Dict[int, t.List[t.Dict[str, t.Any]]] = {}
2626

27-
def get_collection(self, thread: t.Any = None) -> t.List[t.Dict[str, t.Any]]:
28-
if thread is None:
29-
thread = threading.current_thread()
30-
if thread not in self.collections:
31-
self.collections[thread] = []
32-
return self.collections[thread]
27+
def get_collection(self, thread_id: int = None) -> t.List[t.Dict[str, t.Any]]:
28+
if thread_id is None:
29+
thread_id = threading.get_ident()
30+
if thread_id not in self.collections:
31+
self.collections[thread_id] = []
32+
return self.collections[thread_id]
3333

34-
def clear_collection(self, thread: t.Any = None) -> None:
35-
if thread is None:
36-
thread = threading.current_thread()
37-
if thread in self.collections:
38-
del self.collections[thread]
34+
def clear_collection(self, thread_id: int = None) -> None:
35+
if thread_id is None:
36+
thread_id = threading.get_ident()
37+
if thread_id in self.collections:
38+
del self.collections[thread_id]
3939

40-
def collect(self, item: t.Dict[str, t.Any], thread: t.Any = None) -> None:
41-
self.get_collection(thread).append(item)
40+
def collect(self, item: t.Dict[str, t.Any], thread_id: int = None) -> None:
41+
self.get_collection(thread_id).append(item)
4242

4343

4444
class ThreadTrackingHandler(logging.Handler):
@@ -91,15 +91,15 @@ async def process_request(self, request: Request) -> Response:
9191
return await super().process_request(request)
9292

9393
if is_coroutine(endpoint):
94-
self.current_thread = threading.current_thread()
94+
self.thread_id = threading.get_ident()
9595
else:
96-
self.current_thread = await run_in_threadpool(threading.current_thread)
96+
self.thread_id = await run_in_threadpool(threading.get_ident)
9797

98-
collector.clear_collection(thread=self.current_thread)
98+
collector.clear_collection(thread_id=self.thread_id)
9999
return await super().process_request(request)
100100

101101
async def generate_stats(self, request: Request, response: Response) -> Stats:
102-
records = collector.get_collection(thread=self.current_thread)
103-
self._records[self.current_thread] = records
104-
collector.clear_collection(thread=self.current_thread)
102+
records = collector.get_collection(thread_id=self.thread_id)
103+
self._records[self.thread_id] = records
104+
collector.clear_collection(thread_id=self.thread_id)
105105
return {"records": records}

0 commit comments

Comments
 (0)