且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过检测按键来打破 Python 中的这个循环

更新时间:2022-04-28 08:52:29

你希望你的代码更像这样:

You want your code to be more like this:

from subprocess import call

while True:
    try:
        call(["raspivid -n -b 2666666.67 -t 5000 -o test.mp4"], shell=True)
        call(["raspivid -n -b 2666666.67 -t 5000 -o test1.mp4"], shell=True)
    except KeyboardInterrupt:
        break  # The answer was in the question!

break一个完全符合您预期的循环.

You break a loop exactly how you would expect.