File tree Expand file tree Collapse file tree 5 files changed +16
-31
lines changed
services/web/server/src/simcore_service_webserver Expand file tree Collapse file tree 5 files changed +16
-31
lines changed Original file line number Diff line number Diff line change 88from collections .abc import AsyncIterator , Callable
99
1010from aiohttp import web
11+ from common_library .async_utils import cancel_and_wait
1112from tenacity import retry
1213from tenacity .before_sleep import before_sleep_log
1314from tenacity .wait import wait_exponential
@@ -67,10 +68,6 @@ async def _cleanup_ctx_fun(
6768 yield
6869
6970 # tear-down
70- task .cancel ()
71- try :
72- await task
73- except asyncio .CancelledError :
74- assert task .cancelled () # nosec
71+ await cancel_and_wait (task )
7572
7673 return _cleanup_ctx_fun
Original file line number Diff line number Diff line change 1- """ Setup and running of periodic background task
1+ """Setup and running of periodic background task
22
33
44Specifics of the gc implementation should go into garbage_collector_core.py
99from collections .abc import AsyncGenerator
1010
1111from aiohttp import web
12+ from common_library .async_tools import cancel_and_wait
1213from servicelib .logging_utils import log_context
1314
1415from ._core import collect_garbage
@@ -49,18 +50,14 @@ async def run_background_task(app: web.Application) -> AsyncGenerator:
4950
5051 # TEAR-DOWN -----
5152 # controlled cancelation of the gc task
52- try :
53- _logger .info ("Stopping garbage collector..." )
53+ _logger .info ("Stopping garbage collector..." )
5454
55- ack = gc_bg_task .cancel ()
56- assert ack # nosec
55+ ack = gc_bg_task .cancel ()
56+ assert ack # nosec
5757
58- app [_GC_TASK_CONFIG ]["force_stop" ] = True
58+ app [_GC_TASK_CONFIG ]["force_stop" ] = True
5959
60- await gc_bg_task
61-
62- except asyncio .CancelledError :
63- assert gc_bg_task .cancelled () # nosec
60+ await cancel_and_wait (gc_bg_task )
6461
6562
6663async def _collect_garbage_periodically (app : web .Application ):
Original file line number Diff line number Diff line change 11"""
2- Scheduled tasks addressing users
2+ Scheduled tasks addressing users
33
44"""
55
88from collections .abc import AsyncIterator , Callable
99
1010from aiohttp import web
11+ from common_library .async_utils import cancel_and_wait
1112from servicelib .logging_utils import log_context
1213from tenacity import retry
1314from tenacity .before_sleep import before_sleep_log
@@ -55,10 +56,6 @@ async def _cleanup_ctx_fun(
5556 yield
5657
5758 # tear-down
58- task .cancel ()
59- try :
60- await task
61- except asyncio .CancelledError :
62- assert task .cancelled () # nosec
59+ await cancel_and_wait (task )
6360
6461 return _cleanup_ctx_fun
Original file line number Diff line number Diff line change 88from collections .abc import AsyncIterator , Callable
99
1010from aiohttp import web
11+ from common_library .async_utils import cancel_and_wait
1112from models_library .users import UserID
1213from servicelib .logging_utils import get_log_record_extra , log_context
1314from tenacity import retry
@@ -107,10 +108,6 @@ async def _cleanup_ctx_fun(
107108 yield
108109
109110 # tear-down
110- task .cancel ()
111- try :
112- await task
113- except asyncio .CancelledError :
114- assert task .cancelled () # nosec
111+ await cancel_and_wait (task )
115112
116113 return _cleanup_ctx_fun
Original file line number Diff line number Diff line change 55from typing import Any
66
77from aiohttp import web
8+ from common_library .async_utils import cancel_and_wait
89from models_library .api_schemas_webserver .wallets import PaymentID , PaymentMethodID
910from pydantic import HttpUrl , TypeAdapter
1011from servicelib .aiohttp .typing_extension import CleanupContextFunc
@@ -143,10 +144,6 @@ async def _cleanup_ctx_fun(
143144 yield
144145
145146 # tear-down
146- task .cancel ()
147- try :
148- await task
149- except asyncio .CancelledError :
150- assert task .cancelled () # nosec
147+ await cancel_and_wait (task )
151148
152149 return _cleanup_ctx_fun
You can’t perform that action at this time.
0 commit comments