在Python3上使用input()时出现EOF异常

时间:2018-07-01 21:51:33

标签: python python-3.x exception eof

我有以下函数使我发生EOF异常:

def timeTracker(veiksmai, directory, cap, ipAddress):

while not is_non_zero(str(cap)):
    pass
print("Capture started confirmed")
print(veiksmai)
print(len(veiksmai))
print('|    Time, s |   Event   |', file=open(str(directory), 'a'))
startTime = time.time()
i = 0
while i != len(veiksmai):
    print('|    ' + str(round(time.time() - startTime)) + ' |   ' + veiksmai[i] + '   |\n', file=open(str(directory), 'a'))
    input("Press enter for next")
    i += 1

我在这条线上出现异常:

input("Press enter for next")

例外情况如下:

File "/home/dovydas/PycharmProjects/packet-capture/main_new.py", line 29, in timeTracker
input("Press enter for next")
EOFError: EOF when reading a line

我正在使用最新的PyCharm和Python 3.6.5

我已经用Google搜索了该问题,但据我所知,使用PyCharm不会有任何问题。

我尝试创建一个空变量,例如:

var1 = input("Press enter for next")

但这没有帮助。任何帮助表示赞赏!

更新:

这是主要方法:

ipAddress = input("Enter ip address which you want to capture: ")
capDir = input("Enter directory of capture file: ")
timeDir = input("Enter directory of timeline file: ")


actions = []
userInput = ""
while userInput != "DONE":
    userInput = input('Enter next action: ')
    if userInput != 'DONE':
        actions.append(userInput)


if __name__ == '__main__':
    q = Queue()
    p = Process(target=capture, args=(ipAddress, capDir,))
    p.start()

    p2 = Process(target=timeTracker, args=(actions, timeDir, capDir, ipAddress,))
    p2.start()

1 个答案:

答案 0 :(得分:0)

问题在于multiprocessing.Process明确关闭了stdin and opens /dev/null,而标准输入是input的读取位置。您可以考虑改用subprocessthreads