Skip to content

Commit

Permalink
BUG: Cleanup Isolation tasks (#2603)
Browse files Browse the repository at this point in the history
  • Loading branch information
codingl2k1 authored Dec 3, 2024
1 parent 8dd5715 commit 3a3dd7e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ zip_safe = False
include_package_data = True
packages = find:
install_requires =
xoscar>=0.3.0,<0.4.2
xoscar>=0.4.4
torch
gradio
pillow
Expand Down
2 changes: 1 addition & 1 deletion xinference/deploy/docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# required
xoscar>=0.3.0,<0.4.2
xoscar>=0.4.4
gradio==4.26.0
typer[all]<0.12.0 # fix typer required by gradio
pillow
Expand Down
2 changes: 1 addition & 1 deletion xinference/deploy/docker/requirements_cpu.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xoscar>=0.3.0,<0.4.2
xoscar>=0.4.4
gradio==4.26.0
typer[all]<0.12.0
pillow
Expand Down
24 changes: 24 additions & 0 deletions xinference/isolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ def _run(self):
asyncio.set_event_loop(self._loop)
self._stopped = asyncio.Event()
self._loop.run_until_complete(self._stopped.wait())
self._cancel_all_tasks(self._loop)

@staticmethod
def _cancel_all_tasks(loop):
to_cancel = asyncio.all_tasks(loop)
if not to_cancel:
return

for task in to_cancel:
task.cancel()

loop.run_until_complete(asyncio.gather(*to_cancel, return_exceptions=True))

for task in to_cancel:
if task.cancelled():
continue
if task.exception() is not None:
loop.call_exception_handler(
{
"message": "unhandled exception during asyncio.run() shutdown",
"exception": task.exception(),
"task": task,
}
)

def start(self):
if self._threaded:
Expand Down

0 comments on commit 3a3dd7e

Please sign in to comment.