connectors/PYRO/__init__.py
changeset 1982 092d98d56995
parent 1919 ccea0fa6ea91
child 1995 691d119ba20f
equal deleted inserted replaced
1981:d0718654d9b0 1982:092d98d56995
   146         """
   146         """
   147         def __init__(self):
   147         def __init__(self):
   148             # for safe use in from debug thread, must create a copy
   148             # for safe use in from debug thread, must create a copy
   149             self.RemotePLCObjectProxyCopy = None
   149             self.RemotePLCObjectProxyCopy = None
   150 
   150 
   151         def GetPyroProxy(self):
       
   152             """
       
   153             This func returns the real Pyro Proxy.
       
   154             Use this if you musn't keep reference to it.
       
   155             """
       
   156             return RemotePLCObjectProxy
       
   157 
       
   158         def _PyroStartPLC(self, *args, **kwargs):
   151         def _PyroStartPLC(self, *args, **kwargs):
   159             """
   152             return RemotePLCObjectProxy.StartPLC(*args, **kwargs)
   160             confnodesroot._connector.GetPyroProxy() is used
       
   161             rather than RemotePLCObjectProxy because
       
   162             object is recreated meanwhile,
       
   163             so we must not keep ref to it here
       
   164             """
       
   165             current_status, _log_count = confnodesroot._connector.GetPyroProxy().GetPLCstatus()
       
   166             if current_status == "Dirty":
       
   167                 # Some bad libs with static symbols may polute PLC
       
   168                 # ask runtime to suicide and come back again
       
   169 
       
   170                 confnodesroot.logger.write(_("Force runtime reload\n"))
       
   171                 confnodesroot._connector.GetPyroProxy().ForceReload()
       
   172                 confnodesroot._Disconnect()
       
   173                 # let remote PLC time to resurect.(freeze app)
       
   174                 sleep(0.5)
       
   175                 confnodesroot._Connect()
       
   176             self.RemotePLCObjectProxyCopy = copy.copy(confnodesroot._connector.GetPyroProxy())
       
   177             return confnodesroot._connector.GetPyroProxy().StartPLC(*args, **kwargs)
       
   178         StartPLC = PyroCatcher(_PyroStartPLC, False)
   153         StartPLC = PyroCatcher(_PyroStartPLC, False)
   179 
   154 
   180         def _PyroGetTraceVariables(self):
   155         def _PyroGetTraceVariables(self):
   181             """
   156             """
   182             for safe use in from debug thread, must use the copy
   157             for use from debug thread, use a copy
       
   158             pyro creates a new thread on server end proxy object is copied
   183             """
   159             """
   184             if self.RemotePLCObjectProxyCopy is None:
   160             if self.RemotePLCObjectProxyCopy is None:
   185                 self.RemotePLCObjectProxyCopy = copy.copy(confnodesroot._connector.GetPyroProxy())
   161                 self.RemotePLCObjectProxyCopy = copy.copy(RemotePLCObjectProxy)
   186             return self.RemotePLCObjectProxyCopy.GetTraceVariables()
   162             return self.RemotePLCObjectProxyCopy.GetTraceVariables()
   187         GetTraceVariables = PyroCatcher(_PyroGetTraceVariables, ("Broken", None))
   163         GetTraceVariables = PyroCatcher(_PyroGetTraceVariables, ("Broken", None))
   188 
   164 
   189         def _PyroGetPLCstatus(self):
   165         def _PyroGetPLCstatus(self):
   190             return RemotePLCObjectProxy.GetPLCstatus()
   166             return RemotePLCObjectProxy.GetPLCstatus()