UI improvement for asyncio (#6905)

This commit is contained in:
Simon Mo
2020-01-27 12:45:51 -08:00
committed by GitHub
parent bde575b8dd
commit 396d7fafc8
13 changed files with 143 additions and 47 deletions
+34 -1
View File
@@ -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