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

Commit

Permalink
feat: display kernel-pull-progress using tqdm
Browse files Browse the repository at this point in the history
  • Loading branch information
youngjun0627 committed Sep 6, 2021
1 parent e3b7892 commit f7fafe5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/181.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display kernel-pull-progress from background-task-reporter
21 changes: 21 additions & 0 deletions src/ai/backend/client/func/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,27 @@ async def get_or_create(
rqst.set_json(params)
async with rqst.fetch() as resp:
data = await resp.json()
with tqdm(total=100, unit='%') as pbar:
task_id = data['background_task']
bgtask = resp.session.BackgroundTask(task_id)
async with bgtask.listen_events() as response:
async for ev in response:
progress = json.loads(ev.data)
if ev.event == 'bgtask_updated':
current = progress['current_progress']
total = progress['total_progress']
if total == 0:
total = 1e-2
pbar.n = round(current / total * 100, 2)
pbar.update(0)
pbar.refresh()
elif ev.event == 'bgtask_done':
pbar.n = 100.0
pbar.update(0)
pbar.refresh()
pbar.clear()
async with rqst.fetch() as resp:
data = await resp.json()
o = cls(name, owner_access_key) # type: ignore
if api_session.get().api_version[0] >= 5:
o.id = UUID(data['sessionId'])
Expand Down

0 comments on commit f7fafe5

Please sign in to comment.