这里使用pause()函数有什么用(关于raspberry pi)以及它为什么写到底?
#!/usr/bin/env python3
from gpiozero import Button
from signal import pause
import os, sys
offGPIO = int(sys.argv[1]) if len(sys.argv) >= 2 else 21
holdTime = int(sys.argv[2]) if len(sys.argv) >= 3 else 6
# the function called to shut down the RPI
def shutdown():`enter code here`
os.system("sudo poweroff")
btn = Button(offGPIO, hold_time=holdTime)
btn.when_held = shutdown
pause() # handle the button presses in the background
答案 0 :(得分:1)
导致进程一直处于睡眠状态,直到收到信号为止;适当的 然后将调用handler。什么都不返回不在Windows上。 (见 Unix手册页信号(2)。)