3030
3131
3232@contextmanager
33- def warn_if_slow (prefix , * , limit = 0.1 ):
33+ def warn_if_slow (prefix , * , level = logging . WARNING , limit = 0.1 ):
3434 monotonic = time .monotonic ()
3535 process = time .process_time ()
3636 thread = time .thread_time ()
@@ -39,7 +39,7 @@ def warn_if_slow(prefix, *, limit=0.1):
3939 process = time .process_time () - process
4040 thread = time .thread_time () - thread
4141 if monotonic > limit :
42- logging .warning ( "%s: real %.3f>%.3f, process %.3f, thread %.3f" , prefix , monotonic , limit , process , thread )
42+ logging .log ( level , "%s: real %.3f>%.3f, process %.3f, thread %.3f" , prefix , monotonic , limit , process , thread )
4343
4444
4545class Action (Enum ):
@@ -228,13 +228,13 @@ def __init__(self) -> None:
228228 async def _poll_step_save (self ):
229229 # save changes
230230 if self .save_scheduled :
231- with warn_if_slow ("save changes" ):
231+ with warn_if_slow ("save changes" , level = logging . DEBUG ):
232232 await self .save ()
233233
234234 async def _poll_step_reacquire (self ):
235235 # try to re-acquire orphaned resources
236236 async with self .lock :
237- with warn_if_slow ("reacquire orphaned resources" ):
237+ with warn_if_slow ("reacquire orphaned resources" , limit = 3.0 ):
238238 await self ._reacquire_orphaned_resources ()
239239
240240 async def _poll_step_schedule (self ):
@@ -266,21 +266,21 @@ async def save(self):
266266 logging .debug ("Running Save" )
267267 self .save_scheduled = False
268268
269- with warn_if_slow ("create resources snapshot" ):
269+ with warn_if_slow ("create resources snapshot" , level = logging . DEBUG ):
270270 resources = copy .deepcopy (self ._get_resources ())
271- with warn_if_slow ("create places snapshot" ):
271+ with warn_if_slow ("create places snapshot" , level = logging . DEBUG ):
272272 places = copy .deepcopy (self ._get_places ())
273273
274274 def save_sync (resources , places ):
275- with warn_if_slow ("dump resources" ):
275+ with warn_if_slow ("dump resources" , level = logging . DEBUG ):
276276 resources = yaml .dump (resources )
277277 resources = resources .encode ()
278- with warn_if_slow ("dump places" ):
278+ with warn_if_slow ("dump places" , level = logging . DEBUG ):
279279 places = yaml .dump (places )
280280 places = places .encode ()
281- with warn_if_slow ("write resources" ):
281+ with warn_if_slow ("write resources" , level = logging . DEBUG ):
282282 atomic_replace ("resources.yaml" , resources )
283- with warn_if_slow ("write places" ):
283+ with warn_if_slow ("write places" , level = logging . DEBUG ):
284284 atomic_replace ("places.yaml" , places )
285285
286286 await self .loop .run_in_executor (None , save_sync , resources , places )
0 commit comments