停止脚本,EOFError:阅读lin时出现EOF

2024-10-01 04:55:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我运行一个脚本来执行多个进程,这些进程在不同的类中执行。除非用户要求,否则进程不会结束。所以在main类中,我决定创建一个进程来exit()脚本,我想这也会杀死所有进程。这是主.py班级。在

def finishTest():
    end = "notexit"
    while end != "exit":
        end = input("To finish the test type 'exit'")
    exit()


if __name__ == '__main__':

    fT = Process (target=finishTest)
    fT.start()
    #this are functions of this class that call functions from other classes that run the other processes.
    askTest()
    execTest()

当我执行主.py出现以下错误:

^{pr2}$

如何更正此错误?这不是停止脚本和脚本执行的所有进程的正确方法吗?在

谢谢大家!在


Tags: the用户py脚本that进程main错误
1条回答
网友
1楼 · 发布于 2024-10-01 04:55:56

更改变量exit名称并尝试将其放入try except块中:

def finishTest():
    ex = "notexit"
    while ex != "exit":
        try:
            ex = input("To finish the test type 'exit'")
        except EOFError:
            pass
    exit()

输出

^{pr2}$

相关问题 更多 >