我运行了一个执行多个过程的脚本,这些脚本在不同的类中执行。除非用户要求它,否则该过程不会结束。因此,在主要类中,我决定创建一个将退出()脚本的过程,我认为这也会杀死所有过程。这是Main.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()
当我执行main.py时,出现以下错误,
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "execution.py", line 20, in finishTest
exit = input("To finish the test type 'exit'")
EOFError: EOF when reading a line
如何纠正此错误?这不是停止脚本和脚本执行的所有过程的正确方法吗?
谢谢大家!
更改变量exit
名称,然后尝试将其放在try-except块中:
def finishTest():
ex = "notexit"
while ex != "exit":
try:
ex = input("To finish the test type 'exit'")
except EOFError:
pass
exit()
输出:
To finish the test type 'exit'hey
To finish the test type 'exit'okay
To finish the test type 'exit'bye
To finish the test type 'exit'exit
Process finished with exit code 0