30 lines
948 B
Python
30 lines
948 B
Python
import logging
|
|
logging.basicConfig(format="%(asctime)s/%(levelname)s: [%(module)s] %(message)s", level=logging.INFO)
|
|
|
|
import multiprocessing
|
|
from dataset import random_audio_chunk
|
|
import audiopreprocessing
|
|
from time import sleep
|
|
|
|
origin_queue = multiprocessing.Queue()
|
|
target_queue = multiprocessing.Queue()
|
|
|
|
def worker(orig, targ):
|
|
p = orig.get()
|
|
#out = "PROCESSED" + str(p.absolute())
|
|
out = audiopreprocessing.load_preprocessed_audio(p, 16000, True) # This will cause put to hang
|
|
targ.put(out) # This will hang the process
|
|
|
|
if __name__ == "__main__":
|
|
K = 2
|
|
|
|
for p in random_audio_chunk(K):
|
|
origin_queue.put(p)
|
|
|
|
processes = [multiprocessing.Process(target=worker, args=(origin_queue, target_queue)) for _ in range(K)]
|
|
for p in processes: p.start()
|
|
for p in processes: p.join()
|
|
|
|
logging.critical("Successfully terminated all threads")
|
|
|
|
for _ in range(K): print(target_queue.get()) |