aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyagl/services/taskmanager.py20
-rw-r--r--pyagl/tests/test_taskmanager.py24
2 files changed, 44 insertions, 0 deletions
diff --git a/pyagl/services/taskmanager.py b/pyagl/services/taskmanager.py
index 388b931..488094e 100644
--- a/pyagl/services/taskmanager.py
+++ b/pyagl/services/taskmanager.py
@@ -26,6 +26,8 @@ class TaskManagerService(AGLBaseService):
parser.add_argument('--get_process_list', action='store_true')
parser.add_argument('--get_netstat', action='store_true')
parser.add_argument('--get_load_avg', action='store_true')
+ parser.add_argument('--get_extra_info', help='unique process ID', type=int)
+ parser.add_argument('--kill_process', help='unique process ID', type=int)
def __init__(self, ip, port=None, service='agl-service-taskmanager'):
super().__init__(api='taskmanager', ip=ip, port=port, service=service)
@@ -39,6 +41,12 @@ class TaskManagerService(AGLBaseService):
async def get_netstat(self):
return await self.request('get_netstat')
+ async def kill_process(self, tid=None):
+ return await self.request('kill_process', tid)
+
+ async def get_extra_info(self, tid=None):
+ return await self.request('get_extra_info', tid)
+
async def agent_response(self):
pass
@@ -64,6 +72,18 @@ async def main(loop):
resp = await tasks.afbresponse()
print(resp.data)
+ if args.get_extra_info:
+ msgid = await tasks.get_extra_info(args.get_extra_info)
+ print(f'Sent tid={args.get_extra_info} request with messageid {msgid}')
+ resp = await tasks.afbresponse()
+ print(resp)
+
+ if args.kill_process:
+ msgid = await tasks.kill_process(args.kill_process)
+ print(f'Sent tid={args.kill_process} request with messageid {msgid}')
+ resp = await tasks.afbresponse()
+ print(resp)
+
if args.listener:
for response in nets.listener():
print(response)
diff --git a/pyagl/tests/test_taskmanager.py b/pyagl/tests/test_taskmanager.py
index 10c1855..fc1f489 100644
--- a/pyagl/tests/test_taskmanager.py
+++ b/pyagl/tests/test_taskmanager.py
@@ -21,6 +21,12 @@ import logging
from pyagl.services.base import AFBResponse, AFBT
from pyagl.services.taskmanager import TaskManagerService as TASK
+import multiprocessing
+import time
+
+def action(max):
+ time.sleep(max)
+
pytestmark = [pytest.mark.asyncio, pytest.mark.taskmanager]
@pytest.fixture(scope='module')
@@ -52,3 +58,21 @@ async def test_get_load_avg(event_loop, service: TASK):
msgid = await service.get_load_avg()
resp = await service.afbresponse()
assert resp.status == 'success'
+
+@pytest.mark.xfail(reason='Tests that are known to fail, until the agl-service-taskmanager is fixed in master.')
+async def test_get_extra_info(event_loop, service: TASK):
+ msgid = await service.get_extra_info(1)
+ resp = await service.afbresponse()
+ assert resp.status == 'success'
+
+async def test_kill_process(event_loop, service: TASK):
+ mp1 = multiprocessing.Process(target=action,args=(10,))
+ mp1.start()
+ time.sleep(3)
+ print(f'process id: '+str(mp1.pid))
+ msgid = await service.kill_process(mp1.pid)
+ resp = await service.afbresponse()
+ assert resp.status == 'not-replied'
+ time.sleep(1)
+ assert mp1.is_alive() == False
+