Process pool for audio preparation
This commit is contained in:
parent
60304da5a6
commit
63bc695600
|
@ -92,12 +92,15 @@ class Sample:
|
||||||
self.audio_type = new_audio_type
|
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_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:
|
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):
|
def read_audio_format_from_wav_file(wav_file):
|
||||||
|
|
|
@ -4,7 +4,7 @@ import time
|
||||||
import heapq
|
import heapq
|
||||||
import semver
|
import semver
|
||||||
|
|
||||||
from multiprocessing.dummy import Pool as ThreadPool
|
from multiprocessing import Pool
|
||||||
|
|
||||||
KILO = 1024
|
KILO = 1024
|
||||||
KILOBYTE = 1 * KILO
|
KILOBYTE = 1 * KILO
|
||||||
|
@ -83,7 +83,7 @@ class LimitingPool:
|
||||||
self.process_ahead = os.cpu_count() if process_ahead is None else process_ahead
|
self.process_ahead = os.cpu_count() if process_ahead is None else process_ahead
|
||||||
self.sleeping_for = sleeping_for
|
self.sleeping_for = sleeping_for
|
||||||
self.processed = 0
|
self.processed = 0
|
||||||
self.pool = ThreadPool(processes=processes)
|
self.pool = Pool(processes=processes)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
Loading…
Reference in New Issue