EOF Исключение при использовании input () на Python3 - PullRequest
0 голосов
/ 02 июля 2018

У меня есть следующая функция, генерирующая исключение 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")

Но это не помогло. Любая помощь приветствуется!

UPDATE:

Вот основной метод:

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 голосов
/ 02 июля 2018

Проблема в том, что multiprocessing.Process явно закрывает stdin и открывает /dev/null, а стандартный ввод - это то, откуда input читает. Вместо этого вы можете использовать subprocess или threads.

...