Skip to content

Commit

Permalink
Cancel readout monitor task on error
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jul 18, 2023
1 parent 8fe9dcc commit 55c152d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/gort/devices/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ async def expose(

self.spec_set.last_exposure = self

monitor_task: asyncio.Task | None = None

try:
await self.spec_set._send_command_all(
"expose",
Expand All @@ -153,8 +155,15 @@ async def expose(
self.spec_set.write_to_log("Returning with async readout ongoing.")

except Exception as err:
# Cancel the monitor task
if monitor_task and not monitor_task.done():
monitor_task.cancel()
with suppress(asyncio.CancelledError):
await monitor_task

await self.stop_timer()
self.error = True

raise GortSpecError(f"Exposure failed with error {err}", error_code=301)

return self
Expand Down

0 comments on commit 55c152d

Please sign in to comment.