Prevent double-logging of 'timeout for updates'

This commit is contained in:
Lonami Exo 2022-08-11 10:53:21 +02:00
parent 362d06654f
commit dd55e7c748
2 changed files with 13 additions and 8 deletions

View File

@ -250,7 +250,10 @@ class MessageBox:
elif self.next_deadline in self.map: elif self.next_deadline in self.map:
deadline = min(deadline, self.map[self.next_deadline].deadline) deadline = min(deadline, self.map[self.next_deadline].deadline)
if now > deadline: # asyncio's loop time precision only seems to be about 3 decimal places, so it's possible that
# we find the same number again on repeated calls. Without the "or equal" part we would log the
# timeout for updates several times (it also makes sense to get difference if now is the deadline).
if now >= deadline:
# Check all expired entries and add them to the list that needs getting difference. # Check all expired entries and add them to the list that needs getting difference.
self.getting_diff_for.update(entry for entry, gap in self.possible_gaps.items() if now > gap.deadline) self.getting_diff_for.update(entry for entry, gap in self.possible_gaps.items() if now > gap.deadline)
self.getting_diff_for.update(entry for entry, state in self.map.items() if now > state.deadline) self.getting_diff_for.update(entry for entry, state in self.map.items() if now > state.deadline)

View File

@ -335,13 +335,15 @@ class UpdateMethods:
continue continue
deadline = self._message_box.check_deadlines() deadline = self._message_box.check_deadlines()
try: deadline_delay = deadline - asyncio.get_running_loop().time()
updates = await asyncio.wait_for( if deadline_delay > 0:
self._updates_queue.get(), # Don't bother sleeping and timing out if the delay is already 0 (pollutes the logs).
deadline - asyncio.get_running_loop().time() try:
) updates = await asyncio.wait_for(self._updates_queue.get(), deadline_delay)
except asyncio.TimeoutError: except asyncio.TimeoutError:
self._log[__name__].info('Timeout waiting for updates expired') self._log[__name__].info('Timeout waiting for updates expired')
continue
else:
continue continue
processed = [] processed = []