Skip to content

Commit

Permalink
Merge pull request #52 from simonsobs/dev
Browse files Browse the repository at this point in the history
Set asyncio events in the finally block
  • Loading branch information
TaiSakuma authored Jun 11, 2024
2 parents 840db53 + bbc6f78 commit 8911c7d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions nextline/fsm/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ async def on_enter_running(self, _: EventData) -> None:
run_started = asyncio.Event()

async def run() -> None:
async with self._hook.awith.run(context=self._context):
run_started.set()
self._context.run_arg = None
await self.finish() # type: ignore
self.run_finished.set()
try:
async with self._hook.awith.run(context=self._context):
run_started.set()
finally:
run_started.set() # Ensure to unblock the await
self._context.run_arg = None
try:
await self.finish() # type: ignore
finally:
self.run_finished.set()

self._task = asyncio.create_task(run())
await run_started.wait()
Expand All @@ -71,7 +76,7 @@ async def on_close_while_running(self, _: EventData) -> None:

async def wait(self) -> None:
await self.run_finished.wait()

async def on_enter_finished(self, _: EventData) -> None:
await self._hook.ahook.on_finished(context=self._context)

Expand Down

0 comments on commit 8911c7d

Please sign in to comment.