我正在尝试使用asciimatics和winsound.Beep来创建一个同时播放蜂鸣音的视觉效果,我有两个功能需要同时执行,这样当我的asciimatics视觉开始播放时,蜂鸣音就会发出。请帮帮忙。
发布于 2021-07-23 15:31:34
from threading import Thread
def f():
print("f")
def g():
print("g")
def f_and_g_at_once():
t1 = Thread(target=f)
t2 = Thread(target=g)
t1.start() # returns immediately after the thread starts
t2.start()
f_and_g_at_once()或
from multiprocessing import Process
def f():
print("f")
def g():
print("g")
def f_and_g_at_once():
p1 = Process(target=f)
p2 = Process(target=g)
p1.start() # returns immediately after the process starts
p2.start()
# This condition is important, see:
# https://docs.python.org/3/library/multiprocessing.html#the-spawn-and-forkserver-start-methods
if __name__ == "__main__":
f_and_g_at_once()什么是更好的取决于上下文,但在您的情况下,threading变体将是更好的选择。
https://stackoverflow.com/questions/68501555
复制相似问题