在Python3上使用input()时出现EOF异常
我有以下函数抛出EOF异常:在Python3上使用input()时出现EOF异常,python,python-3.x,exception,eof,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')
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
我在谷歌上搜索过这个问题,但据我所知,使用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()
问题是
多处理。进程
显式关闭,标准输入是输入
读取的位置。你可以考虑使用<代码>子进程< /代码>或<代码>线程< /代码>。你能告诉我们你是怎么调用你的程序的吗?这里的问题是stdin
在调用input
之前是关闭的,这通常是因为没有交互式shell作为stdin
谢谢您的评论。我已经添加了关于调用该方法之前发生的事情的代码段。p2是过程。谢谢