from util.ProcessLogger import ProcessLogger
from util.paths import Bpath
class LocalRuntimeMixin():
self.local_runtime_log = log
self.local_runtime = None
self.local_runtime_tmpdir = None
def StartLocalRuntime(self, taskbaricon=True):
if (self.local_runtime is None) or (self.local_runtime.exitcode is not None):
# create temporary directory for runtime working directory
self.local_runtime_tmpdir = tempfile.mkdtemp()
# choose an arbitrary random port for runtime
self.runtime_port = int(random.random() * 1000) + 61131
self.local_runtime_log.write(_("Starting local runtime...\n"))
self.local_runtime = ProcessLogger(
"\"%s\" \"%s\" -p %s -i localhost %s %s" % (
Bpath("Beremiz_service.py"),
{False: "-x 0", True: "-x 1"}[taskbaricon],
self.local_runtime_tmpdir),
timeout=500, keyword=self.local_runtime_tmpdir,
cwd=self.local_runtime_tmpdir)
self.local_runtime.spin()
def KillLocalRuntime(self):
if self.local_runtime is not None:
self.local_runtime.kill(gently=False)
shutil.rmtree(self.local_runtime_tmpdir)
self.local_runtime = None