A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[V0 Deprecation] Remove unused async_timeout.py (#25190)
Signed-off-by: Woosuk Kwon <woosuk.kwon@berkeley.edu>
Woosuk Kwon committed
Sep 18, 2025 at 13:35 UTC
1c3dad22ff92cbf84e0fa8ad1643c560a07944ea
1 file changed
-173
vllm/engine/async_timeout.py
deleted
-173
@@ -1,173 +0,0 @@
1
-# SPDX-License-Identifier: Apache-2.0
2
-# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
-
4
-# Workaround for https://github.com/python/cpython/issues/86296
5
-#
6
-# From https://github.com/aio-libs/async-timeout/blob/master/async_timeout/__init__.py
7
-# Licensed under the Apache License (Apache-2.0)
8
-
9
-import asyncio
10
-import enum
11
-import sys
12
-from types import TracebackType
13
-from typing import Any, Optional, Type
14
-
15
-if sys.version_info[:2] >= (3, 11):
16
- from asyncio import timeout as asyncio_timeout
17
-else:
18
-
19
- class _State(enum.Enum):
20
- INIT = "INIT"
21
- ENTER = "ENTER"
22
- TIMEOUT = "TIMEOUT"
23
- EXIT = "EXIT"
24
-
25
- class Timeout:
26
- # Internal class, please don't instantiate it directly
27
- # Use timeout() and timeout_at() public factories instead.
28
- #
29
- # Implementation note: `async with timeout()` is preferred
30
- # over `with timeout()`.
31
- # While technically the Timeout class implementation
32
- # doesn't need to be async at all,
33
- # the `async with` statement explicitly points that
34
- # the context manager should be used from async function context.
35
- #
36
- # This design allows to avoid many silly misusages.
37
- #
38
- # TimeoutError is raised immediately when scheduled
39
- # if the deadline is passed.
40
- # The purpose is to time out as soon as possible
41
- # without waiting for the next await expression.
42
-
43
- __slots__ = ("_deadline", "_loop", "_state", "_timeout_handler")
44
-
45
- def __init__(self, deadline: Optional[float],
46
- loop: asyncio.AbstractEventLoop) -> None:
47
- self._loop = loop
48
- self._state = _State.INIT
49
-
50
- self._timeout_handler = None # type: Optional[asyncio.Handle]
51
- if deadline is None:
52
- self._deadline = None # type: Optional[float]
53
- else:
54
- self.update(deadline)
55
-
56
- async def __aenter__(self) -> "Timeout":
57
- self._do_enter()
58
- return self
59
-
60
- async def __aexit__(
61
- self,
62
- exc_type: Optional[Type[BaseException]],
63
- exc_val: Optional[BaseException],
64
- exc_tb: Optional[TracebackType],
65
- ) -> Optional[bool]:
66
- self._do_exit(exc_type)
67
- return None
68
-
69
- @property
70
- def expired(self) -> bool:
71
- """Is timeout expired during execution?"""
72
- return self._state == _State.TIMEOUT
73
-
74
- @property
75
- def deadline(self) -> Optional[float]:
76
- return self._deadline
77
-
78
- def reject(self) -> None:
79
- """Reject scheduled timeout if any."""
80
- # cancel is maybe better name but
81
- # task.cancel() raises CancelledError in asyncio world.
82
- if self._state not in (_State.INIT, _State.ENTER):
83
- raise RuntimeError(f"invalid state {self._state.value}")
84
- self._reject()
85
-
86
- def _reject(self) -> None:
87
- if self._timeout_handler is not None:
88
- self._timeout_handler.cancel()
89
- self._timeout_handler = None
90
-
91
- def shift(self, delay: float) -> None:
92
- """Advance timeout on delay seconds.
93
- The delay can be negative.
94
- Raise RuntimeError if shift is called when deadline is not scheduled
95
- """
96
- deadline = self._deadline
97
- if deadline is None:
98
- raise RuntimeError(
99
- "cannot shift timeout if deadline is not scheduled")
100
- self.update(deadline + delay)
101
-
102
- def update(self, deadline: float) -> None:
103
- """Set deadline to absolute value.
104
- deadline argument points on the time in the same clock system
105
- as loop.time().
106
- If new deadline is in the past the timeout is raised immediately.
107
- Please note: it is not POSIX time but a time with
108
- undefined starting base, e.g. the time of the system power on.
109
- """
110
- if self._state == _State.EXIT:
111
- raise RuntimeError(
112
- "cannot reschedule after exit from context manager")
113
- if self._state == _State.TIMEOUT:
114
- raise RuntimeError("cannot reschedule expired timeout")
115
- if self._timeout_handler is not None:
116
- self._timeout_handler.cancel()
117
- self._deadline = deadline
118
- if self._state != _State.INIT:
119
- self._reschedule()
120
-
121
- def _reschedule(self) -> None:
122
- assert self._state == _State.ENTER
123
- deadline = self._deadline
124
- if deadline is None:
125
- return
126
-
127
- now = self._loop.time()
128
- if self._timeout_handler is not None:
129
- self._timeout_handler.cancel()
130
-
131
- task = asyncio.current_task()
132
- if deadline <= now:
133
- self._timeout_handler = self._loop.call_soon(
134
- self._on_timeout, task)
135
- else:
136
- self._timeout_handler = self._loop.call_at(
137
- deadline, self._on_timeout, task)
138
-
139
- def _do_enter(self) -> None:
140
- if self._state != _State.INIT:
141
- raise RuntimeError(f"invalid state {self._state.value}")
142
- self._state = _State.ENTER
143
- self._reschedule()
144
-
145
- def _do_exit(self, exc_type: Optional[Type[BaseException]]) -> None:
146
- if exc_type is asyncio.CancelledError and \
147
- self._state == _State.TIMEOUT:
148
- self._timeout_handler = None
149
- raise asyncio.TimeoutError
150
- # timeout has not expired
151
- self._state = _State.EXIT
152
- self._reject()
153
- return None
154
-
155
- def _on_timeout(self, task: "Optional[asyncio.Task[Any]]") -> None:
156
- if task:
157
- task.cancel()
158
- self._state = _State.TIMEOUT
159
- # drop the reference early
160
- self._timeout_handler = None
161
-
162
- def asyncio_timeout(delay: Optional[float]) -> Timeout:
163
- """timeout context manager.
164
- Useful in cases when you want to apply timeout logic around block
165
- of code or in cases when asyncio.wait_for is not suitable. For example:
166
- >>> async with timeout(0.001):
167
- ... async with aiohttp.get('https://github.com') as r:
168
- ... await r.text()
169
- delay - value in seconds or None to disable timeout logic
170
- """
171
- loop = asyncio.get_running_loop()
172
- deadline = loop.time() + delay if delay is not None else None
173
- return Timeout(deadline, loop)