mirror of
https://github.com/wassname/ray.git
synced 2026-07-14 11:17:54 +08:00
UI improvement for asyncio (#6905)
This commit is contained in:
@@ -3,8 +3,9 @@ This file should only be imported from Python 3.
|
||||
It will raise SyntaxError when importing from Python 2.
|
||||
"""
|
||||
import asyncio
|
||||
from collections import namedtuple
|
||||
from collections import namedtuple, Counter
|
||||
import time
|
||||
import threading
|
||||
|
||||
import ray
|
||||
|
||||
@@ -96,3 +97,35 @@ def get_async(object_id):
|
||||
user_future.object_id = object_id
|
||||
|
||||
return user_future
|
||||
|
||||
|
||||
class AsyncMonitorState:
|
||||
def __init__(self, loop):
|
||||
self.names = dict()
|
||||
self.names_lock = threading.Lock()
|
||||
|
||||
self.sleep_time = 1.0
|
||||
asyncio.ensure_future(self.monitor(), loop=loop)
|
||||
|
||||
async def monitor(self):
|
||||
while True:
|
||||
await asyncio.sleep(self.sleep_time)
|
||||
all_tasks = self.get_all_task_names()
|
||||
ray.show_in_webui(
|
||||
str(len(all_tasks)), key="Number of concurrent task runing")
|
||||
ray.show_in_webui(
|
||||
str(dict(Counter(all_tasks))), key="Concurrent tasks")
|
||||
|
||||
def register_coroutine(self, coro, name):
|
||||
with self.names_lock:
|
||||
self.names[coro] = name
|
||||
|
||||
def unregister_coroutine(self, coro):
|
||||
with self.names_lock:
|
||||
self.names.pop(coro)
|
||||
|
||||
def get_all_task_names(self):
|
||||
names = []
|
||||
with self.names_lock:
|
||||
names = list(self.names.values())
|
||||
return names
|
||||
|
||||
Reference in New Issue
Block a user