summaryrefslogtreecommitdiff
path: root/library.py
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2017-08-19 11:18:28 +0100
committerMichaël Ball <michael.ball@gmail.com>2017-08-19 11:18:28 +0100
commit3d0bf539ca2909ebf1719d3e35afc778d69358dc (patch)
tree264cbb33a642681c54c5ec8cc52b85f77dd5eda1 /library.py
parentd371717e04e116ed140698195c2d1f089c09b65f (diff)
Manage greenlets in a group
Diffstat (limited to 'library.py')
-rwxr-xr-xlibrary.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/library.py b/library.py
index 272e9e5..c03c858 100755
--- a/library.py
+++ b/library.py
@@ -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):
nt-weight: bold } /* Literal.Number.Integer.Long */
# Please order list alphanumerically
alacritty: https://github.com/aaron-williamson/base16-alacritty
blink: https://github.com/niklaas/base16-blink.git
c_header: https://github.com/m1sports20/base16-c_header
crosh: https://github.com/philj56/base16-crosh
dunst: https://github.com/khamer/base16-dunst
emacs: https://github.com/belak/base16-emacs
fzf: https://github.com/nicodebo/base16-fzf
gnome-terminal: https://github.com/aaron-williamson/base16-gnome-terminal
gtk2: https://github.com/dawikur/base16-gtk2
highlight: https://github.com/bezhermoso/base16-highlight
html-preview: https://github.com/chriskempson/base16-html-preview
i3: https://github.com/khamer/base16-i3
kakoune: https://github.com/leira/base16-kakoune
konsole: https://github.com/cskeeters/base16-konsole
mintty: https://github.com/iamthad/base16-mintty
monodevelop: https://github.com/netpyoung/base16-monodevelop
prism: https://github.com/atelierbram/base16-prism
prompt-toolkit: https://github.com/memeplex/base16-prompt-toolkit
putty: https://github.com/abravalheri/base16-putty
pygments: https://github.com/mohd-akram/base16-pygments
qtcreator: https://github.com/ilpianista/base16-qtcreator
rofi: https://github.com/0xdec/base16-rofi
shell: https://github.com/chriskempson/base16-shell
st: https://github.com/honza/base16-st
stumpwm: https://github.com/tpine/base16-stumpwm
styles: https://github.com/samme/base16-styles
termite: https://github.com/khamer/base16-termite
textmate: https://github.com/chriskempson/base16-textmate
tilix: https://github.com/karlding/base16-tilix
vim: https://github.com/chriskempson/base16-vim
vis: https://github.com/pshevtsov/base16-vis
vscode: https://github.com/golf1052/base16-vscode
windows-command-prompt: https://github.com/iamthad/base16-windows-command-prompt
xcode: https://github.com/kreeger/base16-xcode
xfce4-terminal: https://github.com/afg984/base16-xfce4-terminal
xresources: https://github.com/chriskempson/base16-xresources
zathura: https://github.com/nicodebo/base16-zathura