You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gcloud服务中Gunicorn搭配Webdriver频繁终止问题求助

在Google Cloud Run中运行Selenium WebDriver时服务持续终止的问题

我尝试在Google Cloud Run中运行Selenium WebDriver,但服务持续终止。起初怀疑是内存问题,已将服务配置提升至4GB内存+2个CPU,这对仅初始化WebDriver的操作而言应该足够,但问题依旧。

相关代码

import os
import json
import math
import os.path
import time


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

from flask import Flask

# deploy google service
# https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-python-service
#
#
#  Service URL:  webdriver
app = Flask(__name__)

# driver = webdriver.Chrome()

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)  # this is the error 


@app.route("/")
def collect_data():
    # This will collect and build JSON... later

    game_json = [["One A", "One B"],
                 ["Two A", "Two B", "Two C", "Two D", "Two E", "Two F"],
                 ["Three A", "Three B", "Three C", "Three D"]]
    return game_json


if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))

Requirements.txt内容

Chromedriver-binary==122.0.6237.0.0
Flask==3.0.0
gunicorn==21.2.0
Werkzeug==3.0.1
Selenium==4.16.0

相关日志信息

selenium.common.exceptions.WebDriverException: Message: Service /home/cnb/.cache/selenium/chromedriver/linux64/120.0.6099.109/chromedriver unexpectedly exited. Status code was: 127
DEFAULT 2024-01-11T00:50:12.755795Z [2024-01-11 00:50:12 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:10)
DEFAULT 2024-01-11T00:50:13.955768Z [2024-01-11 00:50:13 +0000] [1] [ERROR] Worker (pid:10) was sent SIGKILL! Perhaps out of memory?

已尝试的操作

  • 调整requirements.txt的各种配置,包括使用pip freeze > requirements.txt,不确定是否需要Chromedriver依赖
  • 将Cloud Run的内存配置提升至32GB,仍出现相同的127状态码错误

本地调试遇到的问题

  • Windows 11环境下,PyCharm社区版2023.2.5中无法连接Docker守护进程,找不到docker.exe
  • 安装Docker Desktop后,Docker Engine无法启动,提示意外WSL错误;尝试重置为出厂设置、禁用VPN均无效,日志显示缺失docker-desktop的WSL发行版
  • 当前环境:Windows 11、PyCharm 2023.2.5(社区版),已安装com.jetbrains.edu和Docker插件

内容的提问来源于stack exchange,提问作者Ian Symonds

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 08:50:24