diff --git a/util/audio.py b/util/audio.py index cad596d7..e2469e8a 100644 --- a/util/audio.py +++ b/util/audio.py @@ -92,12 +92,15 @@ class Sample: self.audio_type = new_audio_type +def _change_audio_type(sample_and_audio_type): + sample, audio_type = sample_and_audio_type + sample.change_audio_type(audio_type) + return sample + + def change_audio_types(samples, audio_type=AUDIO_TYPE_PCM, processes=None, process_ahead=None): - def change_audio_type(sample): - sample.change_audio_type(audio_type) - return sample with LimitingPool(processes=processes, process_ahead=process_ahead) as pool: - yield from pool.imap(change_audio_type, samples) + yield from pool.imap(_change_audio_type, map(lambda s: (s, audio_type), samples)) def read_audio_format_from_wav_file(wav_file): diff --git a/util/helpers.py b/util/helpers.py index 73cd9b74..c158066d 100644 --- a/util/helpers.py +++ b/util/helpers.py @@ -4,7 +4,7 @@ import time import heapq import semver -from multiprocessing.dummy import Pool as ThreadPool +from multiprocessing import Pool KILO = 1024 KILOBYTE = 1 * KILO @@ -83,7 +83,7 @@ class LimitingPool: self.process_ahead = os.cpu_count() if process_ahead is None else process_ahead self.sleeping_for = sleeping_for self.processed = 0 - self.pool = ThreadPool(processes=processes) + self.pool = Pool(processes=processes) def __enter__(self): return self