Skip to content

Commit ceb3456

Browse files
committed
refactor: simplify executor cancellation helper
1 parent 70301bd commit ceb3456

1 file changed

Lines changed: 6 additions & 21 deletions

File tree

lmdeploy/utils.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,15 @@
1616

1717

1818
async def await_executor_future(future: asyncio.Future):
19-
"""Await executor work without releasing a lock before cancellation
20-
ends."""
21-
cancelled = False
22-
while not future.done():
23-
try:
24-
result = await asyncio.shield(future)
25-
except asyncio.CancelledError:
26-
cancelled = True
27-
except Exception:
28-
if cancelled:
29-
raise asyncio.CancelledError
30-
raise
31-
else:
32-
if cancelled:
33-
raise asyncio.CancelledError
34-
return result
35-
36-
if cancelled:
19+
"""Await executor work without releasing a lock before it finishes."""
20+
try:
21+
return await asyncio.shield(future)
22+
except asyncio.CancelledError:
3723
try:
38-
future.exception()
24+
await future
3925
except BaseException:
4026
pass
41-
raise asyncio.CancelledError
42-
return future.result()
27+
raise
4328

4429

4530
class _ASNI_COLOR:

0 commit comments

Comments
 (0)