--- a/Beremiz_service.py Tue Apr 16 14:45:41 2019 +0200
+++ b/Beremiz_service.py Thu Apr 18 14:42:23 2019 +0200
@@ -532,7 +532,8 @@
pyro_thread_started = Lock()
pyro_thread_started.acquire()
pyro_thread = Thread(target=pyroserver.PyroLoop,
- kwargs=dict(when_ready=pyro_thread_started.release))
+ kwargs=dict(when_ready=pyro_thread_started.release), # Wait for pyro thread to be effective
@@ -557,7 +558,7 @@
ui_thread_target = app.MainLoop
- ui_thread = Thread(target=ui_thread_target)
+ ui_thread = Thread(target=ui_thread_target, name="UIThread") # This order ui loop to unblock main thread when ready.
@@ -581,6 +582,7 @@
plcobj = runtime.GetPLCObjectSingleton()
@@ -588,7 +590,9 @@
--- a/ProjectController.py Tue Apr 16 14:45:41 2019 +0200
+++ b/ProjectController.py Thu Apr 18 14:42:23 2019 +0200
@@ -1446,13 +1446,13 @@
def UpdateMethodsFromPLCStatus(self):
+ status = PlcStatus.Disconnected if self._connector is not None:
PLCstatus = self._connector.GetPLCstatus()
if PLCstatus is not None:
status, log_count = PLCstatus
self.UpdatePLCLog(log_count)
+ if status == PlcStatus.Disconnected: self._SetConnector(None, False)
status = PlcStatus.Disconnected
if self.previous_plcstate != status:
--- a/runtime/PLCObject.py Tue Apr 16 14:45:41 2019 +0200
+++ b/runtime/PLCObject.py Thu Apr 18 14:42:23 2019 +0200
@@ -388,7 +388,7 @@
self.PythonThreadCondLock = Lock()
self.PythonThreadCond = Condition(self.PythonThreadCondLock)
self.PythonThreadCmd = "Wait"
- self.PythonThread = Thread(target=self.PythonThreadProc)
+ self.PythonThread = Thread(target=self.PythonThreadProc, name="PLCPythonThread") self.PythonThread.start()
@@ -477,8 +477,14 @@
+ def GetPLCstatus(self): + return self._GetPLCstatus() + return (PlcStatus.Disconnected, None) - def GetPLCstatus(self):
+ def _GetPLCstatus(self): return self.PLCStatus, map(self.GetLogCount, xrange(LogLevelsCount))
@@ -645,7 +651,7 @@
self.LastSwapTrace = time()
if self.TraceThread is None and self.PLCStatus == PlcStatus.Started:
- self.TraceThread = Thread(target=self.TraceThreadProc)
+ self.TraceThread = Thread(target=self.TraceThreadProc, name="PLCTrace") --- a/runtime/PyroServer.py Tue Apr 16 14:45:41 2019 +0200
+++ b/runtime/PyroServer.py Thu Apr 18 14:42:23 2019 +0200
@@ -12,6 +12,7 @@
from __future__ import absolute_import
from __future__ import print_function
@@ -27,6 +28,7 @@
self.servicepublisher = None
+ self.piper, self.pipew = None, None def _to_be_published(self):
return self.servicename is not None and \
@@ -60,8 +62,11 @@
self.daemon.connect(pyro_obj, "PLCObject")
- self.daemon.requestLoop()
- self.daemon.sock.close()
+ self.piper,self.pipew = os.pipe() + self.daemon.requestLoop(others=[self.piper], callback=lambda x:None) + self.piper, self.pipew = None, None + if hasattr(self,'sock'): + self.daemon.sock.close() @@ -70,6 +75,9 @@
self.continueloop = False
self.daemon.shutdown(True)
+ self.daemon.closedown() + if self.pipew is not None: + os.write(self.pipew, "goodbye") self.servicepublisher = ServicePublisher("PYRO")
--- a/runtime/Worker.py Tue Apr 16 14:45:41 2019 +0200
+++ b/runtime/Worker.py Thu Apr 18 14:42:23 2019 +0200
@@ -21,8 +21,9 @@
def __init__(self, call, *args, **kwargs):
self.job = (call, args, kwargs)
@@ -67,9 +68,11 @@
self._threadID = _thread.get_ident()
_job = job(*args, **kwargs)
+ # _job.success can't be None after do() @@ -99,6 +102,9 @@
# otherwise notify and wait for completion
+ raise EOFError("Worker is disabled") while self.job is not None:
@@ -110,6 +116,9 @@
+ if _job.success is None: + raise EOFError("Worker job was interrupted") @@ -122,6 +131,8 @@