Skip to content
This repository was archived by the owner on Sep 22, 2023. It is now read-only.

Commit 49e939b

Browse files
authored
Add support for forced session termination (#89)
1 parent d18186a commit 49e939b

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changes
22
=======
33

4+
19.09.6 (2020-03-xx)
5+
--------------------
6+
7+
* NEW: Add ``-f`` / ``--forced`` option to ``backend.ai terminate`` command
8+
and add an optional ``forced`` keyword-argument to SDK API (``Kernel.destroy()``). (#89)
9+
410
19.09.5 (2020-03-08)
511
--------------------
612

src/ai/backend/client/cli/run.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,13 @@ def start(image, session_id, owner, # base args
847847

848848
@main.command(aliases=['rm', 'kill'])
849849
@click.argument('session_ids', metavar='SESSID', nargs=-1)
850+
@click.option('-f', '--forced', is_flag=True,
851+
help='Force-terminate the errored sessions (only allowed for admins)')
850852
@click.option('-o', '--owner', '--owner-access-key', metavar='ACCESS_KEY',
851853
help='Specify the owner of the target session explicitly.')
852854
@click.option('-s', '--stats', is_flag=True,
853855
help='Show resource usage statistics after termination')
854-
def terminate(session_ids, owner, stats):
856+
def terminate(session_ids, forced, owner, stats):
855857
'''
856858
Terminate the given session.
857859
@@ -863,7 +865,7 @@ def terminate(session_ids, owner, stats):
863865
for session_id in session_ids:
864866
try:
865867
kernel = session.Kernel(session_id, owner)
866-
ret = kernel.destroy()
868+
ret = kernel.destroy(forced=forced)
867869
except BackendAPIError as e:
868870
print_error(e)
869871
if e.status == 404:

src/ai/backend/client/kernel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def __init__(self, kernel_id: str, owner_access_key: str = None):
195195
self.owner_access_key = owner_access_key
196196

197197
@api_function
198-
async def destroy(self):
198+
async def destroy(self, *, forced: bool = False):
199199
'''
200200
Destroys the compute session.
201201
Since the server literally kills the container(s), all ongoing executions are
@@ -204,6 +204,8 @@ async def destroy(self):
204204
params = {}
205205
if self.owner_access_key:
206206
params['owner_access_key'] = self.owner_access_key
207+
if forced:
208+
params['forced'] = 'true'
207209
rqst = Request(self.session,
208210
'DELETE', '/kernel/{}'.format(self.kernel_id),
209211
params=params)

0 commit comments

Comments
 (0)