I am experimenting with different python scripts to run videos and I am encountering a strange error, anytime I start vlc, the rest of the script stops executing.
What am I doing wrong?
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!")
The list that you pass to the subprocess
functions is interpreted as argv
for the program. Since shell=False
by default, no interpretation is done on the arguments. Specifically, &
is passed as the last argument to vlc
, and does not start a background process.
To start a background process, call Popen
directly. call
will always wait for the subprocess to complete, so it's not what you want.