mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2026-02-02 05:34:30 +01:00
little improvements in processManager class
This commit is contained in:
parent
5bc5fae9b2
commit
bb1fd118f5
|
|
@ -32,15 +32,12 @@ class ProcessManager:
|
||||||
self._processHandle = None
|
self._processHandle = None
|
||||||
self._textMode = textMode
|
self._textMode = textMode
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
self.stop()
|
|
||||||
|
|
||||||
def addArgument(self, arg):
|
def addArgument(self, arg):
|
||||||
"""!add a new argument
|
"""!add a new argument
|
||||||
|
|
||||||
@param arg: argument to add as string"""
|
@param arg: argument to add as string"""
|
||||||
logging.debug("add argument to process: %s -> %s", self._args[0], arg)
|
logging.debug("add argument to process: %s -> %s", self._args[0], arg)
|
||||||
self._args.append(arg)
|
self._args.append(arg.split())
|
||||||
|
|
||||||
def clearArguments(self):
|
def clearArguments(self):
|
||||||
"""!clear all arguments"""
|
"""!clear all arguments"""
|
||||||
|
|
@ -48,25 +45,24 @@ class ProcessManager:
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""!start the new process"""
|
"""!start the new process"""
|
||||||
logging.debug("start new process: %s", self._args[0])
|
logging.debug("start new process: %s", self._args)
|
||||||
self._processHandle = subprocess.Popen(self._args,
|
try:
|
||||||
stdin=self._stdin,
|
self._processHandle = subprocess.Popen(self._args,
|
||||||
stdout=self._stdout,
|
stdin=self._stdin,
|
||||||
stderr=self._stderr,
|
stdout=self._stdout,
|
||||||
universal_newlines=self._textMode)
|
stderr=self._stderr,
|
||||||
|
universal_newlines=self._textMode)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logging.error("File not found: %s", self._args[0])
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""!Stop the process by sending SIGTERM and wait for ending
|
"""!Stop the process by sending SIGTERM and wait for ending"""
|
||||||
|
|
||||||
@return return code of process"""
|
|
||||||
if self._processHandle and self.isRunning:
|
if self._processHandle and self.isRunning:
|
||||||
logging.debug("stopping process: %s", self._args[0])
|
logging.debug("stopping process: %s", self._args[0])
|
||||||
self._processHandle.terminate()
|
self._processHandle.terminate()
|
||||||
while self.isRunning:
|
while self.isRunning:
|
||||||
pass
|
pass
|
||||||
return self._processHandle.returnCode
|
logging.debug("cannot stop - process not running: %s", self._args[0])
|
||||||
logging.debug("process not running: %s", self._args[0])
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def readline(self):
|
def readline(self):
|
||||||
"""!Read one line from stdout stream
|
"""!Read one line from stdout stream
|
||||||
|
|
|
||||||
22
bw_client.py
22
bw_client.py
|
|
@ -32,8 +32,6 @@ logging.debug("BOSWatch client has started ...")
|
||||||
logging.debug("Import python modules")
|
logging.debug("Import python modules")
|
||||||
import argparse
|
import argparse
|
||||||
logging.debug("- argparse")
|
logging.debug("- argparse")
|
||||||
import subprocess
|
|
||||||
logging.debug("- subprocess")
|
|
||||||
import time
|
import time
|
||||||
logging.debug("- time")
|
logging.debug("- time")
|
||||||
|
|
||||||
|
|
@ -43,11 +41,31 @@ from boswatch.network.client import TCPClient
|
||||||
from boswatch.network.broadcast import BroadcastClient
|
from boswatch.network.broadcast import BroadcastClient
|
||||||
from boswatch.decoder.decoder import Decoder
|
from boswatch.decoder.decoder import Decoder
|
||||||
from boswatch.utils import header
|
from boswatch.utils import header
|
||||||
|
from boswatch.processManager import ProcessManager
|
||||||
|
|
||||||
|
|
||||||
header.logoToLog()
|
header.logoToLog()
|
||||||
header.infoToLog()
|
header.infoToLog()
|
||||||
|
|
||||||
|
# multimon = ProcessManager("_bin/win/multimon/multimon-ng.exe", True)
|
||||||
|
# multimon.addArgument("-a POCSAG1200")
|
||||||
|
# multimon.addArgument("-t raw")
|
||||||
|
# multimon.addArgument("-v 3")
|
||||||
|
# multimon.addArgument("poc1200.raw")
|
||||||
|
#
|
||||||
|
# multimon.setStderr(None)
|
||||||
|
# multimon.start()
|
||||||
|
#
|
||||||
|
# logging.debug("go")
|
||||||
|
#
|
||||||
|
# while multimon.isRunning:
|
||||||
|
# data = multimon.readline()
|
||||||
|
# if data is not None:
|
||||||
|
# print(data)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# exit()
|
||||||
|
|
||||||
logging.debug("parse args")
|
logging.debug("parse args")
|
||||||
# With -h or --help you get the Args help
|
# With -h or --help you get the Args help
|
||||||
parser = argparse.ArgumentParser(prog="bw_client.py",
|
parser = argparse.ArgumentParser(prog="bw_client.py",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue