我有一个非常简单的测试程序,除了执行一个asyncio
事件循环外什么都不做:
import asyncio
asyncio.get_event_loop().run_forever()
当我在Linux上运行这个程序并按下Ctrl+C时,程序会正确地终止并引发一个 KeyboardInterrupt
异常。在Windows上按下Ctrl+C没有任何反应(在Python 3.4.2下测试过)。即使在Windows上,使用time.sleep()
的简单无限循环也可以正确地触发 KeyboardInterrupt
:
import time
while True:
time.sleep(3600)
为什么asyncio的事件循环在Windows上会抑制KeyboardInterrupt信号?