我不能使用pool.starmap
将硒驱动程序作为参数传递给函数。
下面是一个最小的可重现可验证示例:
主代码:
from wait import sleep
import multiprocessing
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.google.com')
secs = [1,2,3,4,5]
if __name__ == "__main__":
with multiprocessing.Pool(processes=4) as pool:
results = pool.starmap(sleep,[(driver,x) for x in secs])
print(results)
Wait.py:
import time
def sleep(driver,t):
time.sleep(t)
return f'slept for {t}'
我收到此错误TypeError: cannot serialize '_io.TextIOWrapper' object
.我该如何解决这个问题?我在网上四处寻找,但找不到答案。
你为什么不使用driver.set_page_load_timeout("time in seconds")
来让司机睡觉?