Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set asyncio events in the finally block #52

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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