File tree Expand file tree Collapse file tree
ddtrace/profiling/collector
tests/profiling/collector Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,6 +143,23 @@ class _ProfiledLock:
143143 except (AttributeError , TypeError ):
144144 pass
145145
146+ # gevent compatibility — gevent's _patch_existing_locks calls
147+ # type(threading.RLock()) to determine the RLock type, then scans gc.get_objects()
148+ # for instances of that type. When our wrapper is on threading.RLock, the type is
149+ # _ProfiledLock, so ALL profiled lock instances match. gevent then checks each for
150+ # _owner/_RLock__owner; without this property, non-RLock wrappers (e.g. Lock) fail
151+ # the check, causing AssertionError("Found unknown lock implementation").
152+ @property
153+ def _owner (self ) -> int | None:
154+ return getattr(self.__wrapped__ , "_owner", None )
155+
156+ @_owner.setter
157+ def _owner(self , value: int ) -> None:
158+ try:
159+ self.__wrapped__._owner = value
160+ except (AttributeError , TypeError ):
161+ pass
162+
146163 # DUNDER methods
147164
148165 def __eq__ (self , other: object ) -> bool:
Original file line number Diff line number Diff line change @@ -208,7 +208,7 @@ def test_lock_patching_survives_module_reimport():
208208 import sys
209209 import threading
210210
211- from ddtrace .profiling .collector ._lock import LockAllocatorWrapper
211+ from ddtrace .profiling .collector ._lock import _LockAllocatorWrapper as LockAllocatorWrapper
212212 from ddtrace .profiling .collector ._lock import _ProfiledLock
213213 from ddtrace .profiling .collector .threading import ThreadingLockCollector
214214
@@ -245,7 +245,7 @@ def test_lock_unpatch_after_module_reimport():
245245 import sys
246246 import threading
247247
248- from ddtrace .profiling .collector ._lock import LockAllocatorWrapper
248+ from ddtrace .profiling .collector ._lock import _LockAllocatorWrapper as LockAllocatorWrapper
249249 from ddtrace .profiling .collector .threading import ThreadingLockCollector
250250
251251 collector = ThreadingLockCollector ()
You can’t perform that action at this time.
0 commit comments