Python中PyAudio和Tkinter的多处理不适用于Mac OS X
我正在尝试使用多处理库创建一个同时包含图像和音频处理的GUI应用程序。但是,在Mac OS X上测试时,相同的代码似乎不起作用,除非我删除import tkinter语句Python中PyAudio和Tkinter的多处理不适用于Mac OS X,python,tkinter,multiprocessing,python-multiprocessing,pyaudio,Python,Tkinter,Multiprocessing,Python Multiprocessing,Pyaudio,我正在尝试使用多处理库创建一个同时包含图像和音频处理的GUI应用程序。但是,在Mac OS X上测试时,相同的代码似乎不起作用,除非我删除import tkinter语句 import pyaudio # The import statement below is causing the problem import tkinter as tki import multiprocessing import threading def do_task(): p = pyaudio.PyA
import pyaudio
# The import statement below is causing the problem
import tkinter as tki
import multiprocessing
import threading
def do_task():
p = pyaudio.PyAudio()
print("Task complete")
if __name__ == '__main__':
p = multiprocessing.Process(target=do_task, args=())
p.start()
# Code works when import statement is placed here
# import tkinter as tki
p.join()
上面的代码在Windows上打印任务完成,在导入语句移位时也打印任务完成,这不是一个好的解决方案,因为我需要在初始化UI后启动多处理
有解决这个问题的方法吗?如果我们知道错误的确切原因,那就好了,如果你能把它复制到它里面就好了^^ 无论如何,我对
多处理.Process
也没有很好的经验,所以我使用线程.Thread
。因此,我定义了一个新类,将Thread
定义为元类,并将运行的函数定义为run
。
e、 g:
我不知道这是否真的有帮助,但我希望如此D
from threading import Thread
class Audio(Thread):
def __init__(self,...):
Thread.__init__(self)
#...
def run(self):
#audio stuff
class GUI(Thread):
def __init__(self,...):
Thread.__init__(self)
#...
def run(self):
#GUI stuff
a,g=Audio(),GUI()
a.start(),g.start()