mirror of
https://github.com/beetbox/beets.git
synced 2026-01-17 05:34:23 +01:00
Added par_map utility
This commit is contained in:
parent
81c5ae3fdf
commit
c4506558f5
1 changed files with 20 additions and 0 deletions
|
|
@ -24,6 +24,7 @@ import re
|
|||
import shutil
|
||||
import fnmatch
|
||||
from collections import Counter
|
||||
from multiprocessing.pool import ThreadPool
|
||||
import traceback
|
||||
import subprocess
|
||||
import platform
|
||||
|
|
@ -1009,3 +1010,22 @@ def asciify_path(path, sep_replace):
|
|||
sep_replace
|
||||
)
|
||||
return os.sep.join(path_components)
|
||||
|
||||
|
||||
def par_map(transform, items):
|
||||
"""
|
||||
This module implements a simple utility to either:
|
||||
a) Perform a parallel map when running under Python >=3
|
||||
b) Perform a sequential map otherwise
|
||||
|
||||
This is useful whenever there is some operation `do_something()` which we
|
||||
want to efficiently apply to our music library.
|
||||
"""
|
||||
if sys.version_info[0] < 3:
|
||||
for item in items:
|
||||
transform(item)
|
||||
else:
|
||||
pool = ThreadPool()
|
||||
pool.map(transform, items)
|
||||
pool.close()
|
||||
pool.join()
|
||||
|
|
|
|||
Loading…
Reference in a new issue