启动 VLC 会停止 python 脚本的其余部分

Starting VLC stops the rest of a python script

我正在尝试对 运行 视频使用不同的 python 脚本,但我遇到了一个奇怪的错误,每当我启动 vlc 时,脚本的其余部分都会停止执行。

我做错了什么?

import time
import subprocess

subprocess.call(["vlc", "myVideo.mp4", "-f", "-L", "--no-audio", "&"])

print("I never print")

time.sleep(5)
subprocess.call(["killall", "-9", "vlc"])
print("I never print either!")

您传递给 subprocess 函数的列表被程序解释为 argv。由于 shell=False 默认情况下,不对参数进行任何解释。具体来说,& 作为最后一个参数传递给 vlc,并且不会启动后台进程。

要启动后台进程,请直接调用 Popencall 会一直等待子进程完成,所以这不是你想要的。