Skip to content

Commit 061d5c4

Browse files
committed
do not use servicelib depenencies
1 parent 152d1f7 commit 061d5c4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/common-library/src/common_library/async_tools.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from inspect import isawaitable
99
from typing import Any, ParamSpec, TypeVar, overload
1010

11-
from servicelib.logging_utils import log_context
12-
1311
_logger = logging.getLogger(__name__)
1412

1513
R = TypeVar("R")
@@ -94,22 +92,24 @@ async def cancel_wait_task(
9492

9593
task.cancel()
9694
try:
97-
with log_context(
98-
_logger, logging.DEBUG, f"Cancelling task {task.get_name()!r}"
99-
):
100-
await asyncio.shield(
101-
# NOTE shield ensures that cancellation of the caller function won't stop you
102-
# from observing the cancellation/finalization of task.
103-
asyncio.wait_for(task, timeout=max_delay)
104-
)
95+
_logger.debug("%s", f"Cancelling task {task.get_name()!r}")
96+
await asyncio.shield(
97+
# NOTE shield ensures that cancellation of the caller function won't stop you
98+
# from observing the cancellation/finalization of task.
99+
asyncio.wait_for(task, timeout=max_delay)
100+
)
105101

106102
except asyncio.CancelledError:
107-
assert task.done() # nosec
108103
current_task = asyncio.current_task()
109104
assert current_task is not None # nosec
110105
if current_task.cancelling() > 0:
111106
# owner function is being cancelled -> propagate cancellation
112107
raise
108+
finally:
109+
if not task.done():
110+
_logger.error("Failed to cancel %s", task.get_name())
111+
else:
112+
_logger.debug("%s", f"Task {task.get_name()!r} cancelled")
113113

114114

115115
def delayed_start(

0 commit comments

Comments
 (0)