为什么使用Ctrl+C键中断会导致代码崩溃?

9 浏览
0 Comments

为什么使用Ctrl+C键中断会导致代码崩溃?

我在编写代码的过程中使用了Ctrl+C来复制和粘贴一些代码。但之后,我的代码因为键盘中断而停止运行。我的代码已经编译并且没有错误。我尝试了另一个文件中不使用Ctrl+C的方法,但是出现了相同的错误。

filename = input('请输入项目名称: ')
codeLine = input(filename + '>')
varDict = {}
varList = []
constDict = {}
constList = []
codeLine = codeLine.strip()
codeLineList = codeLine.split()
while True:
    if codeLine.endswith(";"):
        codeLine = codeLine.rstrip(codeLine[-1])
        if len(codeLineList) == 2:
            if codeLineList[1] == "is":
                varName = (codeLine.split("is")[0]).strip()
                varValue = (codeLine.split("is")[1]).strip()
                varDict[varName] = varValue
                print(varDict)

我得到了以下结果。

请输入项目名称: hi
hi>i is k;

之后没有任何反应。当我调试代码时,我发现了这个错误。

    Traceback (most recent call last):
      File "C:/Users/ajgameboy/PycharmProjects/mylang/main.py", line 9, in 
        codeLine = input(fileName + ">")
    KeyboardInterrupt
    Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)

0