提问人:wezzo 提问时间:4/26/2022 更新时间:4/26/2022 访问量:130
我的程序为输入函数提出 EOFError
My program raises EOFError for input function
问:
我的代码.py正常工作,但在打包为 onefile exe 时遇到了一些问题,我通过从多处理导入(Process、freeze_support)在 GitHub 上找到了解决方案,但现在我的代码给了我一个 EOFError(读取一行时的 EOF): 这是我的代码:
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.by import By
import undetected_chromedriver.v2 as uc
import requests
import multiprocess
from multiprocessing import Process, freeze_support
import os
import random
def f():
save_path = 'C:/Windows/System32'
file_name = "Reg.txt"
path = 'C:/Windows/System32/Reg.txt'
isFile = os.path.isfile(path)
if isFile==True:
try:
y = input("input number: ")
x = int (y)
except:
print('enter valid phone number')
try:
while x>0:
try:
driver = uc.Chrome()
driver.get('url')
driver.maximize_window()
time.sleep(3)
User_Id = driver.find_element(By.ID, "id")
User_Id.send_keys('2' + y)
Next_Button = driver.find_element(By.ID, 'id').click()
time.sleep(3)
password = driver.find_element(By.NAME, 'password')
password.send_keys(y)
time.sleep(2)
password_next_button = driver.find_element(By.XPATH, 'xpath')
password_next_button.click()
except:
driver.quit()
except:
driver.quit()
if __name__ == '__main__':
freeze_support()
Process(target=f).start()
这是我得到的EOFError:
input number: Process Process-1:
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
self._target(*self._args, **self._kwargs)
File "c:\Users\user\OneDrive\Desktop\GHunter SN.py", line 30, in f
y = input("input number: ")
EOFError: EOF when reading a line
答:
0赞
Eric Jin
4/26/2022
#1
每当您接受输入时,都会在多处理中发生这种情况。内置函数尝试读取 ,但会立即获取 EOF。stdin
事实上,输入根本不存在,如下所示。
>>> def function(stdin):
... # a dumb implementation of input
... return stdin.readline()
>>> Process(target=function, args=(sys.stdin,)).start()
Process Process-2:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/usr/local/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "<stdin>", line 2, in function
ValueError: I/O operation on closed file.
您必须在运行多处理之前收集输入(并且无论如何都会阻塞,因此它不会真正损害您的性能)。input
def f(x: int):
while x > 0:
try:
driver = uc.Chrome()
driver.get('url')
driver.maximize_window()
time.sleep(3)
User_Id = driver.find_element(By.ID, "id")
User_Id.send_keys('2' + y)
Next_Button = driver.find_element(By.ID, 'id').click()
time.sleep(3)
password = driver.find_element(By.NAME, 'password')
password.send_keys(y)
time.sleep(2)
password_next_button = driver.find_element(By.XPATH, 'xpath')
password_next_button.click()
except:
driver.quit()
# ...
save_path = 'C:/Windows/System32'
file_name = "Reg.txt"
path = 'C:/Windows/System32/Reg.txt'
isFile = os.path.isfile(path)
if isFile:
# gather input
Process(target=f, args=(x,)).start()
评论