some refactoring

This commit is contained in:
Miroslav Stampar
2011-12-28 16:27:17 +00:00
parent 37d78ffe01
commit 29f502fe29
8 changed files with 25 additions and 47 deletions

View File

@@ -1773,7 +1773,7 @@ def readCachedFileContent(filename, mode='rb'):
"""
if filename not in kb.cache.content:
kb.locks.cacheLock.acquire()
kb.locks.cache.acquire()
if filename not in kb.cache.content:
checkFile(filename)
@@ -1781,7 +1781,7 @@ def readCachedFileContent(filename, mode='rb'):
content = f.read()
kb.cache.content[filename] = content
kb.locks.cacheLock.release()
kb.locks.cache.release()
return kb.cache.content[filename]
@@ -2241,13 +2241,13 @@ def logHTTPTraffic(requestLogMsg, responseLogMsg):
if not conf.trafficFile:
return
kb.locks.logLock.acquire()
kb.locks.log.acquire()
dataToTrafficFile("%s%s" % (requestLogMsg, os.linesep))
dataToTrafficFile("%s%s" % (responseLogMsg, os.linesep))
dataToTrafficFile("%s%s%s%s" % (os.linesep, 76 * '#', os.linesep, os.linesep))
kb.locks.logLock.release()
kb.locks.log.release()
def getPageTemplate(payload, place):
"""

View File

@@ -1437,10 +1437,8 @@ def __setKnowledgeBaseAttributes(flushAll=True):
kb.lastParserStatus = None
kb.locks = AttribDict()
kb.locks.cacheLock = threading.Lock()
kb.locks.logLock = threading.Lock()
kb.locks.ioLock = threading.Lock()
kb.locks.countLock = threading.Lock()
for _ in ("cache", "count", "index", "io", "limits", "log", "outputs", "value"):
kb.locks[_] = threading.Lock()
kb.matchRatio = None
kb.multiThreadMode = False

View File

@@ -188,6 +188,10 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
kb.threadContinue = True
kb.threadException = False
for lock in kb.locks.values():
if lock.locked_lock():
lock.release()
if conf.get("hashDB", None):
conf.hashDB.flush(True)