Skip to content

Commit

Permalink
Create AsyncExitStack using attrs factory
Browse files Browse the repository at this point in the history
  • Loading branch information
injust committed May 12, 2024
1 parent c921db4 commit 0e0b872
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/apscheduler/_schedulers/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class AsyncScheduler:

_state: RunState = attrs.field(init=False, default=RunState.stopped)
_services_task_group: TaskGroup | None = attrs.field(init=False, default=None)
_exit_stack: AsyncExitStack = attrs.field(init=False)
_exit_stack: AsyncExitStack = attrs.field(init=False, factory=AsyncExitStack)
_services_initialized: bool = attrs.field(init=False, default=False)
_scheduler_cancel_scope: CancelScope | None = attrs.field(init=False, default=None)
_running_jobs: set[UUID] = attrs.field(init=False, factory=set)
Expand All @@ -158,13 +158,11 @@ def __attrs_post_init__(self) -> None:
)

async def __aenter__(self) -> Self:
async with AsyncExitStack() as exit_stack:
await self._ensure_services_initialized(exit_stack)
self._services_task_group = await exit_stack.enter_async_context(
create_task_group()
)
exit_stack.callback(setattr, self, "_services_task_group", None)
self._exit_stack = exit_stack.pop_all()
await self._ensure_services_initialized(self._exit_stack)
self._services_task_group = await self._exit_stack.enter_async_context(
create_task_group()
)
self._exit_stack.callback(setattr, self, "_services_task_group", None)

return self

Expand Down

0 comments on commit 0e0b872

Please sign in to comment.