Skip to content

Commit b046908

Browse files
authored
Add timeout support with improved documentation (#983)
1 parent 0bc1dd6 commit b046908

28 files changed

+344
-272
lines changed

CHANGES/983.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Introduce the client-level ``timeout`` configuration which becomes the base timeout configuration while still allowing legacy individual per-API timeouts and merging it into the base timeout. Now setting individual float (total) timeout per-API call is HIGHLY DISCOURAGED in favor of composable timeouts via stdlib's `asyncio.timeout()` async context manager.

CONTRIBUTORS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Gyubong Lee
1515
Hiroki Kiyohara
1616
Igor Alexandrov
1717
Jason Kraus
18+
Jonathan Carroll Otsuka
1819
Joongi Kim
1920
Joshua Chung
2021
Julien Kmec
@@ -26,6 +27,7 @@ Nikolay Novik
2627
Paul Tagliamonte
2728
Robin Tweedie
2829
Sanghun Lee
30+
Saulius Adamonis
2931
Tianon Gravi
3032
Tommy Beadle
3133
Travis DePrato

aiodocker/containers.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from .multiplexed import multiplexed_result_list, multiplexed_result_stream
3131
from .stream import Stream
3232
from .types import JSONObject, MutableJSONObject, PortInfo
33-
from .utils import identical, parse_result
33+
from .utils import _suppress_timeout_deprecation, identical, parse_result
3434

3535

3636
if TYPE_CHECKING:
@@ -286,14 +286,20 @@ async def kill(self, **kwargs) -> None:
286286
):
287287
pass
288288

289-
async def wait(self, *, timeout=None, **kwargs) -> Dict[str, Any]:
290-
data = await self.docker._query_json(
291-
f"containers/{self._id}/wait",
292-
method="POST",
293-
params=kwargs,
294-
timeout=timeout,
295-
)
296-
return data
289+
async def wait(self, *, timeout: float | None = None, **kwargs) -> Dict[str, Any]:
290+
# The wait API is an exception from deprecation of the total timeout.
291+
# Use a context variable to suppress the warning in a thread-safe and async-safe manner.
292+
token = _suppress_timeout_deprecation.set(True)
293+
try:
294+
data = await self.docker._query_json(
295+
f"containers/{self._id}/wait",
296+
method="POST",
297+
params=kwargs,
298+
timeout=timeout,
299+
)
300+
return data
301+
finally:
302+
_suppress_timeout_deprecation.reset(token)
297303

298304
async def delete(self, **kwargs) -> None:
299305
async with self.docker._query(

0 commit comments

Comments
 (0)