내 게시물을 확인해 주셔서 감사합니다.os.system을 반복적으로 호출하면서 무한 루프를 중지하십시오.
import os
print("You can create your own message for alarm.")
user_message = input(">> ")
print("\n<< Sample alarm sound >>")
for time in range(0, 3):
os.system('say ' + user_message) # this code makes sound.
print("\nOkay, The alarm has been set.")
"""
##### My problem is here #####
##### THIS IS NOT STOPPED #####
while True:
try:
os.system('say ' + user_message)
except KeyboardInterrupt:
print("Alarm stopped")
exit(0)
"""
내 문제가 Ctrl + C가 작동하지 않는다는 것입니다 :
먼저, 다음은 내 코드입니다!
try
블록의 위치를 변경하고 신호 (SIGINT) 잡기 기능을 시도했습니다.
그러나 이것도 작동하지 않습니다.
나는이 문제에 대해 https://stackoverflow.com/a/8335212/5247212, https://stackoverflow.com/a/32923070/5247212 및 기타 여러 답변을 보았습니다.
저는 MAC OS (10.12.3) 및 python 3.5.2를 사용하고 있습니다. os.system()
은 C 함수 system()
의 thin 래퍼로
당신이 본 적이 [이 질문] (http://stackoverflow.com/questions/18047657/stop-python-in- terminal-on-mac)? – asongtoruin
윈도우 7과 우분투 14.04에서 잘 작동하는 것으로 보입니다. (분명히 MACOS 특정 "명령"명령을 인쇄물로 대체해야했지만 요점은 ctrl-C가 올바르게 트랩되어 인쇄 된 알람을 인쇄하고 종료 함) – heroworkshop