-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessClass.py
More file actions
38 lines (31 loc) · 1.11 KB
/
ProcessClass.py
File metadata and controls
38 lines (31 loc) · 1.11 KB
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
38
import subprocess
class ControllingProcess:
def __init__(self, ScriptPath, ScriptType):
self.process = None
self.path = ScriptPath
if(ScriptType == "Python"):
self.type = "python"
elif(ScriptType == "Node"):
self.type = "node"
def start(self, name = "Script"):
if(self.process == None):
print("Starting process " + " with path " + self.path + " and type " + self.type + " named " + name)
self.process = subprocess.Popen(self.type + " " + self.path)
else:
self.process.terminate()
self.process = None
self.process = subprocess.Popen(self.type + " " + self.path)
def stop(self):
self.process.terminate()
self.process = None
def is_running(self):
if(self.process != None):
if(self.process.poll() == None):
return True
else:
if(self.process != None):
self.process.terminate()
self.process = None
return False
def wait(self):
self.process.wait()