singleWorkerThread.daemon=True# close the main program even if there are threads left
singleWorkerThread.start()
# Start the thread that calculates POWs
objectProcessorThread=objectProcessor()
objectProcessorThread.daemon=True# close the main program even if there are threads left
objectProcessorThread.start()
# Start the SQL thread
sqlLookup=sqlThread()
sqlLookup.daemon=False# DON'T close the main program even if there are threads left. The closeEvent should command this thread to exit gracefully.
sqlLookup.start()
# Start the thread that calculates POWs
objectProcessorThread=objectProcessor()
objectProcessorThread.daemon=False# DON'T close the main program even the thread remains. This thread checks the shutdown variable after processing each object.
objectProcessorThread.start()
# Start the cleanerThread
singleCleanerThread=singleCleaner()
singleCleanerThread.daemon=True# close the main program even if there are threads left
sqlExecute('''DELETE FROM objectprocessorqueue''')
logger.debug('Loaded %s objects from disk into the objectProcessorQueue.'%str(len(queryreturn)))
defrun(self):
whileTrue:
@ -40,13 +57,29 @@ class objectProcessor(threading.Thread):
self.processmsg(data)
elifobjectType=='broadcast':
self.processbroadcast(data)
elifobjectType=='checkShutdownVariable':# is more of a command, not an object type. Is used to get this thread past the queue.get() so that it will check the shutdown variable.
pass
else:
logger.critical('Error! Bug! The class_objectProcessor was passed an object type it doesn\'t recognize: %s'%str(objectType))
withshared.objectProcessorQueueSizeLock:
shared.objectProcessorQueueSize-=len(data)# We maintain objectProcessorQueueSize so that we will slow down requesting objects if too much data accumulates in the queue.
sql.execute('''INSERT INTO objectprocessorqueue VALUES (?,?)''',
objectType,data)
withshared.objectProcessorQueueSizeLock:
shared.objectProcessorQueueSize-=len(data)# We maintain objectProcessorQueueSize so that we will slow down requesting objects if too much data accumulates in the queue.
logger.debug('Saved %s objects from the objectProcessorQueue to disk. objectProcessorThread exiting.'%str(numberOfObjectsThatWereInTheObjectProcessorQueue))