如何在Heroku中保持硒会话的生命?

时间:2020-10-22 05:01:15

标签: python selenium selenium-webdriver heroku selenium-chromedriver

我已经在heroku中部署了python应用。该应用程序主要用于硒。每当我打开应用程序时,它就会开始新的硒会话。我想在同一个硒会议中发生,这怎么可能? 这是我的chrome_options。

options = Options()
options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
options.add_argument("--disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument('--single-process')
options.add_argument('--disable-gpu')
options.add_argument('--remote-debugging-port=9222')
options.add_argument('--disable-browser-side-navigation')
browser = webdriver.Chrome(options=options, executable_path=os.environ.get("CHROMEDRIVER_PATH"))
options.add_argument("--example-flag")

Procfile

web gunicorn app:app

2 个答案:

答案 0 :(得分:1)

这取决于您如何终止会话

# close the browser window which is currently in focus.
webdriver.close()

# close the browser and terminates the session
webdriver.quit()

在第一种情况下(close()方法),每次执行都会在Webdriver会话仍处于活动状态时打开一个新选项卡

答案 1 :(得分:1)

好的,这是我认为您尚未定义工人的问题。因此,默认情况下Gunicorn开始三个工人,这意味着您要进行三个硒会话,因此将工人限制为一个并设置超时时间

web gunicorn app:app --workers=1 --timeout=50

相关问题