如何通过检测按键来打破 Python 中的这个循环 [英] How to break this loop in Python by detecting key press
本文介绍了如何通过检测按键来打破 Python 中的这个循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
from subprocess import call
try:
while True:
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:
pass
我计划在按下任意按钮时打破循环.但是我尝试了很多方法来破解它,但都没有奏效.
I plan to make it breaking loop while I am pressing any button. However I tried lots of methods to break the and none of them worked.
推荐答案
你希望你的代码更像这样:
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.
这篇关于如何通过检测按键来打破 Python 中的这个循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文