功能以下面的代码为例:使用SIGINT杀死在Python 3
import signal
import time
def stop(signal, frame):
print("You pressed ctrl-c")
# stop counter()
def counter():
for i in range(20):
print(i+1)
time.sleep(0.2)
signal.signal(signal.SIGINT, stop)
while True:
if(input("Do you want to count? ")=="yes"):
counter()
我该如何获得stop()
的杀灭作用,或折断,counter()
功能,所以它返回的提示?
输出例如:
Do you want to count? no
Do you want to count? yes
1
2
3
4
5
6
7
You pressed ctrl-c
Do you want to count?
我使用Python 3.5.2。
我真的很喜欢这个节省的空间量:) –