Daniel Neuhäuser  committed 04a72ea

added multiprocessing, works now about 4 times faster

  • Participants
  • Parent commits 7ffde4c

Comments (0)

Files changed (1)


 from urllib2 import Request, urlopen
 from contextlib import closing, nested
 from optparse import OptionParser
-from itertools import imap
+from itertools import imap, chain
+from multiprocessing import Pool
 from lxml.etree import parse
             if image.text:
                 return image.text
-def process_directory(directory, music_files):
+def process_directory(args):
+    directory, music_files = args
     for music_file in music_files:
         m = get_metadata(music_file)
     if not args:
         parser.error("pass one or more directory paths to the script")
         return False
-    for path in args:
-        for directory, audio_files in iter_directories(path):
-            process_directory(directory, audio_files)
+    # i played around with the number of process a bit and 6 seems to be
+    # optimal for me
+    p = Pool(6)
+        process_directory,
+        chain.from_iterable(imap(iter_directories, args))
+    )
+    p.close()
     return True
 if __name__ == "__main__":