fix locking

This commit is contained in:
Michael Davidsaver
2013-03-31 17:44:51 -04:00
parent 5a5fbddc27
commit 40714ca0fa

View File

@ -76,29 +76,29 @@ def _default_whendone(type, val, tb):
class IOScanListThread(IOScanListBlock): class IOScanListThread(IOScanListBlock):
_worker = None _worker = None
_worker_lock = threading.Lock()
queuelength=100 queuelength=100
@classmethod @classmethod
def getworker(cls): def getworker(cls):
if cls._worker: with cls._worker_lock:
return cls._worker if cls._worker:
import hooks return cls._worker
T = Worker(max=cls.queuelength) import hooks
hooks.addHook('AtIocExit', T.join) T = Worker(max=cls.queuelength)
T.start() hooks.addHook('AtIocExit', T.join)
cls._worker = T T.start()
return T cls._worker = T
return T
def __init__(self): def __init__(self):
super(IOScanListThread,self).__init__() super(IOScanListThread,self).__init__()
self._lock = threading.Lock() self._lock = threading.Lock()
def add(self, rec): def add(self, rec):
print self,'add',rec
with self._lock: with self._lock:
return super(IOScanListThread,self).add(rec) return super(IOScanListThread,self).add(rec)
def _remove(self, rec): def _remove(self, rec):
print self,'remove',rec
with self._lock: with self._lock:
return super(IOScanListThread,self)._remove(rec) return super(IOScanListThread,self)._remove(rec)