Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
fc1493a0
Unverified
Commit
fc1493a0
authored
Aug 07, 2024
by
Nick Hill
Committed by
GitHub
Aug 07, 2024
Browse files
[FrontEnd] Make `merge_async_iterators` `is_cancelled` arg optional (#7282)
parent
311f7438
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
vllm/utils.py
vllm/utils.py
+6
-5
No files found.
vllm/utils.py
View file @
fc1493a0
...
...
@@ -405,7 +405,7 @@ async def iterate_with_cancellation(
async
def
merge_async_iterators
(
*
iterators
:
AsyncGenerator
[
T
,
None
],
is_cancelled
:
Callable
[[],
Awaitable
[
bool
]],
is_cancelled
:
Optional
[
Callable
[[],
Awaitable
[
bool
]]
]
=
None
,
)
->
AsyncGenerator
[
Tuple
[
int
,
T
],
None
]:
"""Merge multiple asynchronous iterators into a single iterator.
...
...
@@ -413,8 +413,8 @@ async def merge_async_iterators(
When it yields, it yields a tuple (i, item) where i is the index of the
iterator that yields the item.
It also polls
the
provided function at least once per second
to check
for client cancellation.
It also
optionally
polls
a
provided function at least once per second
to check
for client cancellation.
"""
# Can use anext() in python >= 3.10
...
...
@@ -422,12 +422,13 @@ async def merge_async_iterators(
ensure_future
(
pair
[
1
].
__anext__
()):
pair
for
pair
in
enumerate
(
iterators
)
}
timeout
=
None
if
is_cancelled
is
None
else
1
try
:
while
awaits
:
done
,
pending
=
await
asyncio
.
wait
(
awaits
.
keys
(),
return_when
=
FIRST_COMPLETED
,
timeout
=
1
)
if
await
is_cancelled
():
timeout
=
timeout
)
if
is_cancelled
is
not
None
and
await
is_cancelled
():
raise
asyncio
.
CancelledError
(
"client cancelled"
)
for
d
in
done
:
pair
=
awaits
.
pop
(
d
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment