@@ -171,7 +171,7 @@ def _acquire(self, inner_func, *args, **kwargs):
171171
172172 self ._self_recorder .push_event (event )
173173 except Exception as e :
174- LOG .warning ( "Error recording lock acquire event: %s" , e )
174+ LOG .debug ( "Failed to record a lock acquire event: %s" , e )
175175 pass # nosec
176176
177177 def acquire (self , * args , ** kwargs ):
@@ -263,42 +263,36 @@ def _find_self_name(self, var_dict: typing.Dict):
263263 return None
264264
265265 # Get lock acquire/release call location and variable name the lock is assigned to
266+ # This function propagates ValueError if the frame depth is <= 3.
266267 def _maybe_update_self_name (self ):
267268 if self ._self_name is not None :
268269 return
269- try :
270- # We expect the call stack to be like this:
271- # 0: this
272- # 1: _acquire/_release
273- # 2: acquire/release (or __enter__/__exit__)
274- # 3: caller frame
275- if config .enable_asserts :
276- frame = sys ._getframe (1 )
277- if frame .f_code .co_name not in {"_acquire" , "_release" }:
278- raise AssertionError ("Unexpected frame %s" % frame .f_code .co_name )
279- frame = sys ._getframe (2 )
280- if frame .f_code .co_name not in {
281- "acquire" ,
282- "release" ,
283- "__enter__" ,
284- "__exit__" ,
285- "__aenter__" ,
286- "__aexit__" ,
287- }:
288- raise AssertionError ("Unexpected frame %s" % frame .f_code .co_name )
289- frame = sys ._getframe (3 )
290-
291- # First, look at the local variables of the caller frame, and then the global variables
292- self ._self_name = self ._find_self_name (frame .f_locals ) or self ._find_self_name (frame .f_globals )
293-
294- if not self ._self_name :
295- self ._self_name = ""
296- LOG .debug (
297- "Failed to get lock variable name, we only support local/global variables and their attributes."
298- )
299-
300- except Exception as e :
301- LOG .warning ("Error getting lock acquire/release call location and variable name: %s" , e )
270+ # We expect the call stack to be like this:
271+ # 0: this
272+ # 1: _acquire/_release
273+ # 2: acquire/release (or __enter__/__exit__)
274+ # 3: caller frame
275+ if config .enable_asserts :
276+ frame = sys ._getframe (1 )
277+ if frame .f_code .co_name not in {"_acquire" , "_release" }:
278+ raise AssertionError ("Unexpected frame %s" % frame .f_code .co_name )
279+ frame = sys ._getframe (2 )
280+ if frame .f_code .co_name not in {
281+ "acquire" ,
282+ "release" ,
283+ "__enter__" ,
284+ "__exit__" ,
285+ "__aenter__" ,
286+ "__aexit__" ,
287+ }:
288+ raise AssertionError ("Unexpected frame %s" % frame .f_code .co_name )
289+ frame = sys ._getframe (3 )
290+
291+ # First, look at the local variables of the caller frame, and then the global variables
292+ self ._self_name = self ._find_self_name (frame .f_locals ) or self ._find_self_name (frame .f_globals )
293+
294+ if not self ._self_name :
295+ self ._self_name = ""
302296
303297
304298class FunctionWrapper (wrapt .FunctionWrapper ):
0 commit comments