RasPi 3 Python:Popen为什么会打断while循环?

时间:2019-03-28 04:33:24

标签: python-3.x raspberry-pi3 raspbian

我想用每个命令播放两个视频,并尝试也停止它们,但是当我运行代码时,它会播放,但是while循环结束或整个程序被杀死。

这是代码:

import os
import sys
from time import sleep
from subprocess import Popen

movie1 = ("/home/pi/Downloads/movie1.mp4")
movie2 = ("/home/pi/Downloads/movie2.mp4")

def vPlay(video):

    os.system('killall omxplayer.bin')
    omxc = Popen(['omxplayer', '-b', video])
    sleep(1)


if __name__ == "__main__":

    while True:
        print("Command:")
        x = input()

        if x == 'q':

            vPlay(movie1)
            omxc = Popen(['omxplayer','i'])

        elif x == 'w':

            vPlay(movie2)
            omxc = Popen(['omxplayer','i'])

        elif x == 'e':
            os.system('killall omxplayer.bin')

这是终端:

>>> %Run sys.py
Command:
q
omxplayer.bin: no process found
Command:

========================= RESTART =========================
>>> 

请帮助我找到一些解决此问题的方法。谢谢

0 个答案:

没有答案