diff options
author | Michaël Ball <michael.ball@gmail.com> | 2017-08-19 11:18:28 +0100 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2017-08-19 11:18:28 +0100 |
commit | 3d0bf539ca2909ebf1719d3e35afc778d69358dc (patch) | |
tree | 264cbb33a642681c54c5ec8cc52b85f77dd5eda1 /library.py | |
parent | d371717e04e116ed140698195c2d1f089c09b65f (diff) |
Manage greenlets in a group
Diffstat (limited to 'library.py')
-rwxr-xr-x | library.py | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -3,10 +3,11 @@ import logging import os -from gevent import joinall, monkey, queue, sleep, spawn +from gevent import monkey, queue +from gevent.pool import Group import mutagen import six -from six.moves import configparser +from six.moves import configparser, range from db.db_manager import DbManager from models.track import Track @@ -44,12 +45,12 @@ class MediaLibrary(object): file_queue (Queue[str]): A queue containing file paths. """ - while not file_queue.empty(): + try: path = file_queue.get() metadata = mutagen.File(path, easy=True) Track.store(_u(path), metadata, self.__database) - - sleep(0) + except queue.Empty: + pass def run(self, path=None): """Store all tracks located in the supplied path. @@ -102,7 +103,13 @@ class MediaLibrary(object): file_queue.put(file_path) _LOGGER.info("Storing tracks") - joinall([spawn(self.store_track_task, file_queue)] * 18) + + tasks = Group() + for i in range(file_queue.qsize()): + tasks.spawn(self.store_track_task, file_queue) + + tasks.join() + _LOGGER.info("Done") def delete_file(self, path): |