From dabff7a4d5e0286e652fbedd5e04f10683bbea81 Mon Sep 17 00:00:00 2001 From: iPAS Date: Fri, 4 Jan 2019 16:53:52 +0700 Subject: [PATCH] Fix the problem when process openplc defunct after being stopped. --- webserver/openplc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webserver/openplc.py b/webserver/openplc.py index 74a8b2a..9ef58de 100755 --- a/webserver/openplc.py +++ b/webserver/openplc.py @@ -76,7 +76,7 @@ class runtime: def start_runtime(self): if (self.status() == "Stopped"): - a = subprocess.Popen(['./core/openplc']) + self.theprocess = subprocess.Popen(['./core/openplc']) # XXX: iPAS self.runtime_status = "Running" def stop_runtime(self): @@ -88,6 +88,10 @@ class runtime: data = s.recv(1000) s.close() self.runtime_status = "Stopped" + + while self.theprocess.poll() is None: # XXX: iPAS, to prevent the defunct killed process. + time.sleep(1) # https://www.reddit.com/r/learnpython/comments/776r96/defunct_python_process_when_using_subprocesspopen/ + except socket.error as serr: print("Failed to stop the runtime. Error: " + str(serr))