首先,我是个初学者.

import os
import subprocess
import multiprocessing
import threading
from playsound import playsound
CurrentPath = os.path.dirname(os.path.normpath(__file__))
os.chdir(CurrentPath)

def music():
    Music = "Music.mp4"
    #subprocess.run(["ffplay", "-nodisp", "-autoexit", "-hide_banner", Music])
    playsound("Music.mp4")

def other_things():
    print("Hello World")

#musicp = multiprocessing.Process(target=music())
#restp = multiprocessing.Process(target=other_things())
musicp = threading.Thread(target=music())
restp = threading.Thread(target=other_things())

restp.start()
musicp.start()

正如你所看到的,我甚至try 了多线程,但它仍然要等到音乐结束后才能进入其余的代码.

推荐答案

不要调用线程函数的目标参数中的函数-删除括号以引用函数,而不是其返回值

musicp = threading.Thread(target=music) # instead of music()
restp = threading.Thread(target=other_things) # instead of other_things()

Python相关问答推荐

流畅的模式,采用Escc方法

在Python中是否可以输入使用任意大小参数列表的第一个元素的函数

除了Python之外,可以替代bare?

customtkinter中使用的这个小部件的名称是什么

"如果发生特定错误,返回值

PyQt5如何将pyuic 5生成的Python类添加到QStackedWidget中?

为什么dict(id=1,**{id:2})有时会引发KeyMessage:id而不是TypMessage?

更改Seaborn条形图中的x轴日期时间限制

无法使用python.h文件; Python嵌入错误

在函数内部使用eval(),将函数的输入作为字符串的一部分

Class_weight参数不影响RandomForestClassifier不平衡数据集中的结果

理解Python的二分库:澄清bisect_left的使用

Pandas 在最近的日期合并,考虑到破产

管道冻结和管道卸载

在极性中创建条件累积和

如何指定列数据类型

为什么numpy. vectorize调用vectorized函数的次数比vector中的元素要多?

如何在Python中使用另一个数据框更改列值(列表)

从Windows Python脚本在WSL上运行Linux应用程序

使用BeautifulSoup抓取所有链接