我不久前开始使用多处理,它正在处理基本示例。之后我尝试实现某种多声音输入程序,并尝试通过队列将输入通量引导到某个处理模块,但目前严重失败。我将用 3 点来描述我的问题:文件夹结构、流程结构、我尝试过的内容。
文件夹结构
- 根文件夹
- 应用
- 启动应用程序.py
- input_cfg.ini
- 核
- 核心.py
- gui.py
- audio_recorder.py(使用 sounddevice.InputStream)
- x_recorder.py
- 应用
进程结构 当我开始运行我的应用程序时,会调用 gui 并在我按下开始按钮后创建进程。
- 主要流程
- audio_recorder_1 进程
- audio_recorder_进程
- 申请流程
我试过的
核心.py
from multiprocessing import Queue, Process
central_queue = Queue()
...
d = {}
d['output'] = central_queue
o = AudioRecorder('name', **d)
启动应用程序.py
import core
def handle_queue_data():
while True:
print(str(core.central_queue.get()))
if __name__ == "__main__":
Process(target=handle_queue_data, name="syncOutput").start()
audio_recorder.py
class AudioRecorder(object):
def __init__(self, name, **d):
...
self.output_queue = d['output']
def run(self):
queue = Queue()
def callback(indata, frames, time, status):
if status:
print(status, flush=True)
# Push the got data into the queue
queue.put([indata.copy()])
with sd.InputStream(samplerate=self.sample_rate, device=self.device_id, channels=self.channel_id, callback=callback):
while True:
self.output_queue.put(queue.get())
它不起作用。调试后,似乎从core.py
记录器开始后,队列的引用发生了变化......仅供参考调试信息:
# in the audio_recorder.py object
centralized_queue = {Queue} <multiprocessing.queues.Queue object at 0x00000000086B3320>
_buffer = {deque} deque([[array([[-0.01989746, -0.02053833],\n [-0.01828003, -0.0196228 ],\n [-0.00634766, -0.00686646],\n ..., \n [-0.01119995, -0.01144409],\n [-0.00900269, -0.00982666],\n [-0.00823975, -0.00888062]], dtype=float32)]])
_close = {Finalize} <Finalize object, callback=_finalize_close, args=[deque([[array([[-0.01989746, -0.02053833],\n [-0.01828003, -0.0196228 ],\n [-0.00634766, -0.00686646],\n ..., \n [-0.01119995, -0.01144409],\n [-0.00900269, -0.00982666],\n [-0
_closed = {bool} False
_ignore_epipe = {bool} False
_joincancelled = {bool} False
_jointhread = {Finalize} <Finalize object, callback=_finalize_join, args=[<weakref at 0x00000000083A2638; to 'Thread' at 0x0000000004DF1B00>], exitprority=-5>
_maxsize = {int} 2147483647
_notempty = {Condition} <Condition(<unlocked _thread.lock object at 0x0000000004738198>, 0)>
_opid = {int} 1320
_reader = {PipeConnection} <multiprocessing.connection.PipeConnection object at 0x00000000086B34A8>
_rlock = {Lock} <Lock(owner=None)>
_sem = {BoundedSemaphore} <BoundedSemaphore(value=2147483645, maxvalue=2147483647)>
_thread = {Thread} <Thread(QueueFeederThread, started daemon 9344)>
_wlock = {NoneType} None
_writer = {PipeConnection} <multiprocessing.connection.PipeConnection object at 0x00000000086B3518>
# in the handle_queue_data
centralized_queue = {Queue} <multiprocessing.queues.Queue object at 0x000000000479DA20>
_buffer = {deque} deque([])
_close = {NoneType} None
_closed = {bool} False
_ignore_epipe = {bool} False
_joincancelled = {bool} False
_jointhread = {NoneType} None
_maxsize = {int} 2147483647
_notempty = {Condition} <Condition(<unlocked _thread.lock object at 0x00000000058C8350>, 0)>
_opid = {int} 7208
_reader = {PipeConnection} <multiprocessing.connection.PipeConnection object at 0x000000000684C438>
_rlock = {Lock} <Lock(owner=None)>
_sem = {BoundedSemaphore} <BoundedSemaphore(value=2147483647, maxvalue=2147483647)>
_thread = {NoneType} None
_wlock = {NoneType} None
_writer = {PipeConnection} <multiprocessing.connection.PipeConnection object at 0x00000000058DE6A0>
之后我也尝试使用不同的东西,都失败了,我无法传递数据......队列是否有可能在这里是可变对象?或者多处理中存在错误(非常不可能)或者与 sounddevice 的组合使队列不稳定?
对不起,我的描述很长...
我提前感谢您的帮助!
最好的问候,
塞巴斯蒂安