1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +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")
scanner = Scanner(db.session)
while self.__queue:
path = sorted(self.__queue.iteritems(), key = lambda i: i[1])[0][0]
path = self.__next_item()
while path:
self.__logger.info("Scanning: '%s'", path)
scanner.scan_file(path)
del self.__queue[path]
path = self.__next_item()
db.session.commit()
db.session.remove()
@ -116,6 +115,18 @@ class ScannerProcessingQueue(Thread):
self.__cond.notify()
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 not config.check():
sys.exit(1)