簡體   English   中英

如何在heroku中保持硒會話?

[英]How to keep the selenium session alive in heroku?

我已經在 heroku 中部署了 python 應用程序。 該應用程序主要使用硒。 每當我打開應用程序時,它都會啟動新的硒會話。 我想在同一個 selenium 會話中實現,這怎么可能? 這是我的 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")

配置文件

web gunicorn app:app

這取決於您如何終止會話

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

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

在第一種情況下( close()方法),每次執行都會在 Webdriver 會話仍處於活動狀態時打開一個新選項卡

好的,這是我認為您尚未定義工人的問題。 因此,默認情況下Gunicorn啟動三個工作人員,這意味着在您的情況下進行三個硒會話,因此將工作人員限制為一個並設置超時

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM