Fix the problem when process openplc defunct after being stopped.

This commit is contained in:
iPAS 2019-01-04 16:53:52 +07:00
parent ebf57a3da6
commit dabff7a4d5
1 changed files with 5 additions and 1 deletions

View File

@ -76,7 +76,7 @@ class runtime:
def start_runtime(self): def start_runtime(self):
if (self.status() == "Stopped"): if (self.status() == "Stopped"):
a = subprocess.Popen(['./core/openplc']) self.theprocess = subprocess.Popen(['./core/openplc']) # XXX: iPAS
self.runtime_status = "Running" self.runtime_status = "Running"
def stop_runtime(self): def stop_runtime(self):
@ -88,6 +88,10 @@ class runtime:
data = s.recv(1000) data = s.recv(1000)
s.close() s.close()
self.runtime_status = "Stopped" 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: except socket.error as serr:
print("Failed to stop the runtime. Error: " + str(serr)) print("Failed to stop the runtime. Error: " + str(serr))