我只是注意到我的笔记本电脑(戴尔XPS 15z)上没有BREAK键(没有专用的数字键盘).我正在逐步运行调试器,然后当一切看起来都很好时,我就让它发挥出来.然而,它正在无限循环中运行,现在我意识到没有休息键就没有办法阻止它!
这是一个糟糕的笑话吗?我不得不重启电脑; 有更优雅的方式吗?
谢谢.
from socket import socket, AF_INET, SOCK_STREAM
sock = socket(AF_INET, SOCK_STREAM)
sock.bind(("localhost", 7777))
sock.listen(1)
while True:
try:
connection, address = sock.accept()
print("connected from " + address)
received_message = sock.recv(300)
if not received_message:
break
connection.sendall(b"hello")
except KeyBoardInterrupt:
connection.close()
Run Code Online (Sandbox Code Playgroud)
所以我试图把我的头包裹在套接字并拥有这个非常简单的脚本,但出于某种原因,我不能用a杀死这个脚本 KeyboardInterrupt
我怎么用KeyboardInterrupt
那个杀死脚本,为什么我不能用它杀死它KeyboardInterrupt
?