Fix previous commit : Using wx.CallAfter shouldn't have been necessary, and was a symptom of failing evaluator's deadlock detection.
authorEdouard Tisserant
Thu, 14 Feb 2019 10:06:43 +0100
changeset 2489 27e4fd37fea6
parent 2488 889c43872f4c
child 2490 2d72d8a8d7e5
Fix previous commit : Using wx.CallAfter shouldn't have been necessary, and was a symptom of failing evaluator's deadlock detection.
Beremiz_service.py
wxglade_hmi/wxglade_hmi.py
--- a/Beremiz_service.py	Wed Feb 13 13:08:26 2019 +0100
+++ b/Beremiz_service.py	Thu Feb 14 10:06:43 2019 +0100
@@ -435,6 +435,7 @@
         # UI threads can be either the one from WX main loop or
         # worker thread from twisted "threadselect" reactor
         current_id = currentThread().ident
+
         if ui_thread is not None \
             and ui_thread.ident != current_id \
             and (not havetwisted or (
@@ -570,6 +571,7 @@
     # This order ui loop to unblock main thread when ready.
     if havetwisted:
         def signal_uithread_started():
+            global twisted_reactor_thread_id
             twisted_reactor_thread_id = currentThread().ident
             ui_thread_started.release()
         reactor.callLater(0, signal_uithread_started)
--- a/wxglade_hmi/wxglade_hmi.py	Wed Feb 13 13:08:26 2019 +0100
+++ b/wxglade_hmi/wxglade_hmi.py	Thu Feb 14 10:06:43 2019 +0100
@@ -132,6 +132,9 @@
         else:
             define_hmi = ""
 
+        global_hmi = ("global %s\n" % ",".join(
+            [x["name"] for x in main_frames]) if len(main_frames) > 0 else "")
+
         declare_hmi = \
 "\n".join(["%(name)s = None\n" % x for x in main_frames]) + \
 "\n".join(["\n".join(["%(class)s.%(h)s = %(h)s" %
@@ -142,29 +145,26 @@
     wx.MessageBox(_("Please stop PLC to close"))
 
 def InitHMI():
-"""+"\n".join(["""\
+    """+ global_hmi + "\n" + "\n".join(["""\
     %(name)s = %(class)s(None)
     %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame)
     %(name)s.Show()
 
 """ % x for x in main_frames]) + """\
 def CleanupHMI():
-""" + "\n".join(["""\
+    """+ global_hmi + "\n" + "\n".join(["""\
     if %(name)s is not None: 
         %(name)s.Destroy()
 """ % x for x in main_frames])
 
-        global_hmi = ("global %s\n" % ",".join(
-            [x["name"] for x in main_frames]) if len(main_frames) > 0 else "")
-
         self.PreSectionsTexts = {
             "globals": define_hmi,
             "start":   global_hmi,
-            "stop":    global_hmi + "wx.CallAfter(CleanupHMI)\n"
+            "stop":    "CleanupHMI()\n"
         }
         self.PostSectionsTexts = {
             "globals": declare_hmi,
-            "start":   "wx.CallAfter(InitHMI)\n",
+            "start":   "InitHMI()\n",
         }
 
         if len(main_frames) == 0 and \