30
30
31
31
32
32
@contextmanager
33
- def warn_if_slow (prefix , * , limit = 0.1 ):
33
+ def warn_if_slow (prefix , * , level = logging . WARNING , limit = 0.1 ):
34
34
monotonic = time .monotonic ()
35
35
process = time .process_time ()
36
36
thread = time .thread_time ()
@@ -39,7 +39,7 @@ def warn_if_slow(prefix, *, limit=0.1):
39
39
process = time .process_time () - process
40
40
thread = time .thread_time () - thread
41
41
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 )
43
43
44
44
45
45
class Action (Enum ):
@@ -228,13 +228,13 @@ def __init__(self) -> None:
228
228
async def _poll_step_save (self ):
229
229
# save changes
230
230
if self .save_scheduled :
231
- with warn_if_slow ("save changes" ):
231
+ with warn_if_slow ("save changes" , level = logging . DEBUG ):
232
232
await self .save ()
233
233
234
234
async def _poll_step_reacquire (self ):
235
235
# try to re-acquire orphaned resources
236
236
async with self .lock :
237
- with warn_if_slow ("reacquire orphaned resources" ):
237
+ with warn_if_slow ("reacquire orphaned resources" , limit = 3.0 ):
238
238
await self ._reacquire_orphaned_resources ()
239
239
240
240
async def _poll_step_schedule (self ):
@@ -266,21 +266,21 @@ async def save(self):
266
266
logging .debug ("Running Save" )
267
267
self .save_scheduled = False
268
268
269
- with warn_if_slow ("create resources snapshot" ):
269
+ with warn_if_slow ("create resources snapshot" , level = logging . DEBUG ):
270
270
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 ):
272
272
places = copy .deepcopy (self ._get_places ())
273
273
274
274
def save_sync (resources , places ):
275
- with warn_if_slow ("dump resources" ):
275
+ with warn_if_slow ("dump resources" , level = logging . DEBUG ):
276
276
resources = yaml .dump (resources )
277
277
resources = resources .encode ()
278
- with warn_if_slow ("dump places" ):
278
+ with warn_if_slow ("dump places" , level = logging . DEBUG ):
279
279
places = yaml .dump (places )
280
280
places = places .encode ()
281
- with warn_if_slow ("write resources" ):
281
+ with warn_if_slow ("write resources" , level = logging . DEBUG ):
282
282
atomic_replace ("resources.yaml" , resources )
283
- with warn_if_slow ("write places" ):
283
+ with warn_if_slow ("write places" , level = logging . DEBUG ):
284
284
atomic_replace ("places.yaml" , places )
285
285
286
286
await self .loop .run_in_executor (None , save_sync , resources , places )
0 commit comments