简体   繁体   English

如何在heroku中保持硒会话?

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

I have deployed python app in heroku.我已经在 heroku 中部署了 python 应用程序。 The app is mainly working with selenium.该应用程序主要使用硒。 Whenever i open the app it started new selenium session.每当我打开应用程序时,它都会启动新的硒会话。 I want to make happen in the same selenium session how is it possible?我想在同一个 selenium 会话中实现,这怎么可能? here is my chrome_options.这是我的 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

It depends how you terminate your session这取决于您如何终止会话

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

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

In the first case ( close() method) each execution opens a new tab while the Webdriver session is still active在第一种情况下( close()方法),每次执行都会在 Webdriver 会话仍处于活动状态时打开一个新选项卡

OK here is the problem I think you haven't defined the workers.好的,这是我认为您尚未定义工人的问题。 So By default Gunicorn start three workers which means three selenium session in your case so limit the workers to one and set the time out因此,默认情况下Gunicorn启动三个工作人员,这意味着在您的情况下进行三个硒会话,因此将工作人员限制为一个并设置超时

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM