mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2026-04-05 06:15:31 +00:00
little improvements in processManager class
This commit is contained in:
parent
5bc5fae9b2
commit
bb1fd118f5
2 changed files with 33 additions and 19 deletions
|
|
@ -32,15 +32,12 @@ class ProcessManager:
|
|||
self._processHandle = None
|
||||
self._textMode = textMode
|
||||
|
||||
def __del__(self):
|
||||
self.stop()
|
||||
|
||||
def addArgument(self, arg):
|
||||
"""!add a new argument
|
||||
|
||||
@param arg: argument to add as string"""
|
||||
logging.debug("add argument to process: %s -> %s", self._args[0], arg)
|
||||
self._args.append(arg)
|
||||
self._args.append(arg.split())
|
||||
|
||||
def clearArguments(self):
|
||||
"""!clear all arguments"""
|
||||
|
|
@ -48,25 +45,24 @@ class ProcessManager:
|
|||
|
||||
def start(self):
|
||||
"""!start the new process"""
|
||||
logging.debug("start new process: %s", self._args[0])
|
||||
self._processHandle = subprocess.Popen(self._args,
|
||||
stdin=self._stdin,
|
||||
stdout=self._stdout,
|
||||
stderr=self._stderr,
|
||||
universal_newlines=self._textMode)
|
||||
logging.debug("start new process: %s", self._args)
|
||||
try:
|
||||
self._processHandle = subprocess.Popen(self._args,
|
||||
stdin=self._stdin,
|
||||
stdout=self._stdout,
|
||||
stderr=self._stderr,
|
||||
universal_newlines=self._textMode)
|
||||
except FileNotFoundError:
|
||||
logging.error("File not found: %s", self._args[0])
|
||||
|
||||
def stop(self):
|
||||
"""!Stop the process by sending SIGTERM and wait for ending
|
||||
|
||||
@return return code of process"""
|
||||
"""!Stop the process by sending SIGTERM and wait for ending"""
|
||||
if self._processHandle and self.isRunning:
|
||||
logging.debug("stopping process: %s", self._args[0])
|
||||
self._processHandle.terminate()
|
||||
while self.isRunning:
|
||||
pass
|
||||
return self._processHandle.returnCode
|
||||
logging.debug("process not running: %s", self._args[0])
|
||||
return 0
|
||||
logging.debug("cannot stop - process not running: %s", self._args[0])
|
||||
|
||||
def readline(self):
|
||||
"""!Read one line from stdout stream
|
||||
|
|
@ -112,4 +108,4 @@ class ProcessManager:
|
|||
if self._processHandle.poll() is None:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue