user2790605
user2790605

Reputation: 13

How to make python loop "not waiting" for finish previous command?

I need to open VLC and play video, depending on the variable "start". In this example, loop continues after ad1.mp4 finished. Is there a way, how to make loop not waiting? So ad1.mp4 start playing and loop will continue.


start = 1

while True:
    if start == 1:
        os.system("vlc --video ad/ad1.pm4")
    if start == 2:
        os.system("vlc --video ad/ad2.pm4")
    .
    .
    .

Upvotes: 0

Views: 342

Answers (1)

Felipe Sulser
Felipe Sulser

Reputation: 1195

You can use the subprocess library.

import subprocess
subprocess.Popen(["vlc","--video ","ad/ad1.pm4"])

This allows to spawn a new process and not making python to wait until it finishes.

Library link: https://docs.python.org/3/library/subprocess.html

Upvotes: 1

Related Questions