--- a/svghmi/svghmi.py Thu Nov 03 17:43:30 2022 +0100
+++ b/svghmi/svghmi.py Fri Nov 04 17:38:37 2022 +0100
@@ -641,19 +641,29 @@
svghmi_cmds[thing] = (
"Popen(" +
repr(shlex.split(given_command.format(**svghmi_options))) +
- ")") if given_command else "pass # no command given"
+ ")") if given_command else "None # no command given"
runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str)
runtimefile = open(runtimefile_path, 'w')
runtimefile.write("""
-# TODO : multiple watchdog (one for each svghmi instance)
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# generated by beremiz/svghmi/svghmi.py
+
+browser_proc = None
+
def svghmi_{location}_watchdog_trigger():
- {svghmi_cmds[Watchdog]}
+ global browser_proc
+ restart_proc = {svghmi_cmds[Watchdog]}
+ waitpid_timeout(restart_proc, "SVGHMI watchdog triggered command")
+ waitpid_timeout(browser_proc, "SVGHMI browser process")
+ browser_proc = None
max_svghmi_sessions = {maxConnections_total}
def _runtime_{location}_svghmi_start():
- global svghmi_watchdog, svghmi_servers
+ global svghmi_watchdog, svghmi_servers, browser_proc
srv = svghmi_servers.get("{interface}:{port}", None)
if srv is not None:
@@ -678,7 +688,7 @@
path_list.append("{path}")
- {svghmi_cmds[Start]}
+ browser_proc = {svghmi_cmds[Start]}
if {enable_watchdog}:
if svghmi_watchdog is None:
@@ -691,7 +701,7 @@
def _runtime_{location}_svghmi_stop():
- global svghmi_watchdog, svghmi_servers
+ global svghmi_watchdog, svghmi_servers, browser_proc
if svghmi_watchdog is not None:
svghmi_watchdog.cancel()
@@ -707,7 +717,10 @@
svghmi_listener.stopListening()
svghmi_servers.pop("{interface}:{port}")
- {svghmi_cmds[Stop]}
+ stop_proc = {svghmi_cmds[Stop]}
+ waitpid_timeout(stop_proc, "SVGHMI stop command")
+ waitpid_timeout(browser_proc, "SVGHMI browser process")
+ browser_proc = None
""".format(location=location_str,
xhtml=target_fname,