Skip to content

Commit

Permalink
fixup! fix(tester-present): Kill it with fire
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinandjarisch committed Jan 2, 2024
1 parent 07732df commit fbcea43
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/gallia/services/uds/ecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,22 @@ async def wait_for_ecu(
async def _tester_present_worker(self, interval: float) -> None:
assert self.transport
logger.debug("tester present worker started")
while True:
task = asyncio.current_task()
while task is not None and task.cancelling() == 0:
try:
await asyncio.sleep(interval)
# TODO Only ping if there was no other UDS traffic for `interval` amount of time
await self.ping(UDSRequestConfig(max_retry=1))
except asyncio.CancelledError:
logger.debug("tester present worker terminated")
break
raise
except ConnectionError:
logger.info("connection lost; tester present waiting…")
except Exception as e:
logger.warning(f"Tester present worker got {e!r}")
logger.debug(
"Tester present worker was cancelled but received no asyncio.CancelledError"
)

async def start_cyclic_tester_present(self, interval: float) -> None:
logger.debug("Starting tester present worker")
Expand All @@ -402,12 +406,11 @@ async def stop_cyclic_tester_present(self) -> None:
)
return

running = True
while running:
running = self.tester_present_task.cancel()
logger.debug("Cancelled tester present task")
await asyncio.sleep(0)
await self.tester_present_task
self.tester_present_task.cancel()
try:
await self.tester_present_task
except asyncio.CancelledError:
pass

async def update_state(
self, request: service.UDSRequest, response: service.UDSResponse
Expand Down

0 comments on commit fbcea43

Please sign in to comment.