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:
parent
132d7b0c8b
commit
01c80fed16
@ -80,20 +80,19 @@ class ScannerProcessingQueue(Thread):
|
|||||||
if not self.__queue:
|
if not self.__queue:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
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.remove()
|
||||||
db.session.commit()
|
self.__logger.debug("Freeing scanner")
|
||||||
db.session.remove()
|
del scanner
|
||||||
self.__logger.debug("Freeing scanner")
|
|
||||||
del scanner
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.__running = False
|
self.__running = False
|
||||||
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user