# HG changeset patch # User etisserant # Date 1219680190 -7200 # Node ID d0f7d36bf2419f5bc5a4df6ed742a443b1a4ecb6 # Parent 451bb2c1d1573471aa895a9c42b3a55edd9df251 Added lock to avoid variable subsciption concurrent to transmission to PLC diff -r 451bb2c1d157 -r d0f7d36bf241 plugger.py --- a/plugger.py Mon Aug 25 18:02:15 2008 +0200 +++ b/plugger.py Mon Aug 25 18:03:10 2008 +0200 @@ -600,7 +600,7 @@ ieclib_path = os.path.join(base_folder, "matiec", "lib") # import for project creation timestamping -from threading import Timer +from threading import Timer, Lock from time import localtime from datetime import datetime # import necessary stuff from PLCOpenEditor @@ -663,6 +663,8 @@ # Setup debug information self.IECdebug_callables = {} + self.IECdebug_callables_lock = Lock() + # Timer to prevent rapid-fire when registering many variables self.DebugTimer=Timer(0.5,self.RegisterDebugVarToConnector) self.ResetIECProgramsAndVariables() @@ -1058,6 +1060,7 @@ def RegisterDebugVarToConnector(self): Idxs = [] if self._connector is not None: + self.IECdebug_callables_lock.acquire() for IECPath,WeakCallableDict in self.IECdebug_callables: if len(WeakCallableDict) == 0: # Callable Dict is empty. @@ -1070,6 +1073,7 @@ Idxs.append(Idx) else: self.logger.write_warning("Debug : Unknown variable %s\n"%IECPath) + self.IECdebug_callables_lock.release() self._connector.TraceVariables(Idxs) def SubscribeDebugIECVariable(self, IECPath, callable, *args, **kwargs): @@ -1078,10 +1082,12 @@ to a WeakKeyDictionary linking weakly referenced callables to optionnal args """ + self.IECdebug_callables_lock.acquire() # If no entry exist, create a new one with a fresh WeakKeyDictionary self.IECdebug_callables.setdefault( IECPath, WeakKeyDictionary())[callable]=(args, kwargs) + self.IECdebug_callables_lock.release() # Rearm anti-rapid-fire timer self.DebugTimer.cancel() self.DebugTimer.start()