summaryrefslogtreecommitdiff
path: root/src/apscheduler/datastores
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2022-07-24 14:08:25 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2022-07-24 14:37:52 +0300
commit5c757bff12bc5ca4fecc3ea492285978caad4ec0 (patch)
tree6fb5ed5ad351b7dc32b85fd157c4c61f5b866520 /src/apscheduler/datastores
parentf215c1ab45959095f6b499eb7b26356c5937ee8b (diff)
downloadapscheduler-5c757bff12bc5ca4fecc3ea492285978caad4ec0.tar.gz
Fixed CancelScope errors when the startup or shutdown of AsyncDataStoreAdapter is cancelled
Diffstat (limited to 'src/apscheduler/datastores')
-rw-r--r--src/apscheduler/datastores/async_adapter.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/apscheduler/datastores/async_adapter.py b/src/apscheduler/datastores/async_adapter.py
index 99accd4..6ae51b9 100644
--- a/src/apscheduler/datastores/async_adapter.py
+++ b/src/apscheduler/datastores/async_adapter.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import sys
from datetime import datetime
from typing import Iterable
from uuid import UUID
@@ -31,12 +32,18 @@ class AsyncDataStoreAdapter(BaseAsyncDataStore):
else:
sync_event_broker = SyncEventBrokerAdapter(event_broker, self._portal)
- await to_thread.run_sync(lambda: self.original.start(sync_event_broker))
+ try:
+ await to_thread.run_sync(lambda: self.original.start(sync_event_broker))
+ except BaseException:
+ await self._portal.__aexit__(*sys.exc_info())
+ raise
async def stop(self, *, force: bool = False) -> None:
- await to_thread.run_sync(lambda: self.original.stop(force=force))
- await self._portal.__aexit__(None, None, None)
- await super().stop(force=force)
+ try:
+ await to_thread.run_sync(lambda: self.original.stop(force=force))
+ finally:
+ await self._portal.__aexit__(None, None, None)
+ await super().stop(force=force)
async def add_task(self, task: Task) -> None:
await to_thread.run_sync(self.original.add_task, task)