-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin32_memurai_ctrl.py
37 lines (30 loc) · 942 Bytes
/
win32_memurai_ctrl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
"""----------------------------------------------------------------------------
Author:
Huang Quanyong (wo1fSea)
quanyongh@foxmail.com
Date:
2019/8/4
Description:
win32_memurai_ctrl.py
----------------------------------------------------------------------------"""
import os
import psutil
import subprocess
MEMURAI_PATH = "./memurai/"
class MemuraiController(object):
def __init__(self):
self._pid = None
def start(self):
if self._pid:
self.stop()
p = subprocess.Popen(os.path.join(MEMURAI_PATH, "memurai.exe"))
self._pid = p.pid
def stop(self):
if self._pid:
try:
if self._pid in [p.pid for p in psutil.process_iter()]:
p = psutil.Process(self._pid)
p.kill()
except Exception as ex:
print("MemuraiController stop exception: %s" % ex)