Ejemplo n.º 1
0
 def PythonRuntimeCall(self, methodname, use_evaluator=True, reverse_order=False):
     """
     Calls init, start, stop or cleanup method provided by
     runtime python files, loaded when new PLC uploaded
     """
     methods = self.python_runtime_vars.get("_runtime_%s" % methodname, [])
     if reverse_order:
         methods = reversed(methods)
     for method in methods:
         if use_evaluator:
             _res, exp = self.evaluator(method)
         else:
             _res, exp = default_evaluator(method)
         if exp is not None:
             self.LogMessage(0, '\n'.join(traceback.format_exception(*exp)))
Ejemplo n.º 2
0
    def evaluator(tocall, *args, **kwargs):
        # To prevent deadlocks, check if current thread is not one of the UI
        # 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 (
                    twisted_reactor_thread_id is not None
                    and twisted_reactor_thread_id != current_id)):

            o = type('', (object, ), dict(call=(tocall, args, kwargs),
                                          res=None))
            wx.CallAfter(wx_evaluator, o)
            wx_eval_lock.acquire()
            return o.res
        else:
            # avoid dead lock if called from the wx mainloop
            return default_evaluator(tocall, *args, **kwargs)
Ejemplo n.º 3
0
 def wx_evaluator(obj, *args, **kwargs):
     tocall, args, kwargs = obj.call
     obj.res = default_evaluator(tocall, *args, **kwargs)
     wx_eval_lock.release()