Skip to content

Commit 7695b1a

Browse files
committed
Check for cache content
1 parent ee128f8 commit 7695b1a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

newrelic/core/trace_cache.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import threading
2323
import traceback
2424
import weakref
25-
2625
from collections.abc import MutableMapping
2726

2827
try:
@@ -71,7 +70,7 @@ def get_event_loop(task):
7170
return getattr(task, "_loop", None)
7271

7372

74-
class cached_module():
73+
class cached_module:
7574
def __init__(self, module_path, name=None):
7675
self.module_path = module_path
7776
self.name = name or module_path
@@ -123,9 +122,22 @@ def current_thread_id(self):
123122
# all other cases where we can obtain a current greenlet,
124123
# then it should indicate we are running as a greenlet.
125124

126-
current = self.greenlet.getcurrent()
127-
if current is not None and current.parent:
128-
return id(current)
125+
# current = self.greenlet.getcurrent()
126+
# if current is not None and current.parent:
127+
# return id(current)
128+
129+
# In this case, the garbage collector could have already
130+
# collected the greenlet object, so we need to check if the
131+
# weakref is still alive before we can access the parent
132+
133+
# print(f"cache: {self._cache.data}")
134+
# print(f"thread id: {thread.get_ident()}")
135+
if self._cache.data:
136+
current = self.greenlet.getcurrent()
137+
# print(f"greenlet id: {id(current)}")
138+
if current is not None and current.parent:
139+
# print(f"greenlet id with parent: {id(current)}")
140+
return id(current)
129141

130142
if self.asyncio:
131143
task = current_task(self.asyncio)

0 commit comments

Comments
 (0)