@@ -194,7 +194,8 @@ def __init__(self) -> None:
194
194
self .clients : dict [str , ClientSession ] = {}
195
195
self .load ()
196
196
197
- self .poll_task = asyncio .get_event_loop ().create_task (self .poll ())
197
+ self .loop = asyncio .get_event_loop ()
198
+ self .poll_task = self .loop .create_task (self .poll ())
198
199
199
200
async def _poll_step (self ):
200
201
# save changes
@@ -216,8 +217,7 @@ async def _poll_step(self):
216
217
traceback .print_exc ()
217
218
218
219
async def poll (self ):
219
- loop = asyncio .get_event_loop ()
220
- while not loop .is_closed ():
220
+ while not self .loop .is_closed ():
221
221
try :
222
222
await asyncio .sleep (15.0 )
223
223
await self ._poll_step ()
@@ -247,11 +247,10 @@ async def save(self):
247
247
places = yaml .dump (places )
248
248
places = places .encode ()
249
249
250
- loop = asyncio .get_event_loop ()
251
250
logging .debug ("Awaiting resources" )
252
- await loop .run_in_executor (None , atomic_replace , "resources.yaml" , resources )
251
+ await self . loop .run_in_executor (None , atomic_replace , "resources.yaml" , resources )
253
252
logging .debug ("Awaiting places" )
254
- await loop .run_in_executor (None , atomic_replace , "places.yaml" , places )
253
+ await self . loop .run_in_executor (None , atomic_replace , "places.yaml" , places )
255
254
256
255
def load (self ):
257
256
try :
@@ -310,7 +309,7 @@ async def request_task():
310
309
except Exception :
311
310
logging .exception ("error in client message handler" )
312
311
313
- runnning_request_task = asyncio . get_event_loop () .create_task (request_task ())
312
+ runnning_request_task = self . loop .create_task (request_task ())
314
313
315
314
try :
316
315
async for out_msg in queue_as_aiter (out_msg_queue ):
@@ -406,7 +405,7 @@ async def request_task():
406
405
except Exception :
407
406
logging .exception ("error in exporter message handler" )
408
407
409
- runnning_request_task = asyncio . get_event_loop () .create_task (request_task ())
408
+ runnning_request_task = self . loop .create_task (request_task ())
410
409
411
410
try :
412
411
async for cmd in queue_as_aiter (command_queue ):
0 commit comments