1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

Prevent put() from blocking when the scanner is running

This commit is contained in:
spl0k 2014-07-27 13:20:51 +02:00
parent 132d7b0c8b
commit 01c80fed16

View File

@ -83,12 +83,11 @@ class ScannerProcessingQueue(Thread):
self.__logger.debug("Instantiating scanner") self.__logger.debug("Instantiating scanner")
scanner = Scanner(db.session) scanner = Scanner(db.session)
while self.__queue: path = self.__next_item()
path = sorted(self.__queue.iteritems(), key = lambda i: i[1])[0][0] while path:
self.__logger.info("Scanning: '%s'", path) self.__logger.info("Scanning: '%s'", path)
scanner.scan_file(path) scanner.scan_file(path)
path = self.__next_item()
del self.__queue[path]
db.session.commit() db.session.commit()
db.session.remove() db.session.remove()
@ -116,6 +115,18 @@ class ScannerProcessingQueue(Thread):
self.__cond.notify() self.__cond.notify()
self.__timer = None self.__timer = None
def __next_item(self):
with self.__cond:
if not self.__queue:
return None
next = sorted(self.__queue.iteritems(), key = lambda i: i[1])[0]
if not self.__running or next[1] + 5 < time.time():
del self.__queue[next[0]]
return next[0]
return None
if __name__ == "__main__": if __name__ == "__main__":
if not config.check(): if not config.check():
sys.exit(1) sys.exit(1)