【问题标题】:Gunicorn Command Line Error inGoogle App Engine Standard EnvironmentGoogle App Engine 标准环境中的 Gunicorn 命令行错误
【发布时间】:2018-12-12 03:52:54
【问题描述】:

在将 Flask/Python3/Postgres 应用程序部署到应用程序引擎标准环境后,我收到了源源不断的以下错误。关于 Psycopg2 包的警告值得关注,但不是导致应用程序无法运行的原因。相反,它是 gunicorn 的无效命令行参数,由 GAE 提供,而不是由我提供。是否有人能够成功地将使用 Postgres 的 Python3 Flask 部署到标准环境?

这是日志文件输出:

2018-12-11 02:51:37 +0000] [3738] [INFO] Booting worker with pid: 3738
2018-12-11 02:51:37 default[20181210t140744]  /env/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
2018-12-11 02:51:37 default[20181210t140744]    """)
2018-12-11 02:51:38 default[20181210t211942]  usage: gunicorn [-h] [--debug] [--args]
2018-12-11 02:51:38 default[20181210t211942]  gunicorn: error: unrecognized arguments: main:app --workers 1 -c /config/gunicorn.py
2018-12-11 02:51:38 default[20181210t211942]  [2018-12-11 02:51:38 +0000] [882] [INFO] Worker exiting (pid: 882)

【问题讨论】:

  • 您能出示您的app.yaml 文件吗?你里面有entrypoint吗?

标签: google-app-engine google-cloud-platform gunicorn


【解决方案1】:

默认情况下,如果 app.yaml 中未定义 entrypoint,App Engine 将在 main.py 中查找名为 app 的应用。如果您查看Github 中的官方代码示例,它会在 main.py 文件中声明:

app = Flask(__name__)

或者,这可以通过将entrypoint 添加到指向另一个文件的 app.yaml 来进行配置。例如,如果您在一个名为 prod 的文件中声明应用程序:

entrypoint: gunicorn -b :$PORT prod.app

您将找到有关入口点配置here 的更多详细信息。

【讨论】:

    【解决方案2】:

    根据上面的评论和答案,看来问题必须出在我的应用程序中。我通过在准系统应用程序上本地运行 gunicorn 确认了这一点,但在运行真正的应用程序时失败了。

    一个罪魁祸首原来是使用 argparse,我正在使用它,以便在本地工作时向命令行添加“调试”参数。将该代码移至 if __name__ == '__main__': 部分可以使应用在本地使用 gunicorn 时运行良好。

    但部署到 GAE 时仍然失败:

    2018-12-12 20:09:16 default[20181212t094625]  [2018-12-12 20:09:16 +0000] [8145] [INFO] Booting worker with pid: 8145
    2018-12-12 20:09:16 default[20181212t094625]  /env/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
    2018-12-12 20:09:16 default[20181212t094625]    """)
    2018-12-12 20:09:16 default[20181212t094625]  [2018-12-12 20:09:16 +0000] [8286] [INFO] Booting worker with pid: 8286
    2018-12-12 20:09:16 default[20181212t094625]  /env/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
    2018-12-12 20:09:16 default[20181212t094625]    """)
    2018-12-12 20:09:19 default[20181212t094625]  usage: gunicorn [-h] [--debug] [--args]
    2018-12-12 20:09:19 default[20181212t094625]  gunicorn: error: unrecognized arguments: -b :8081 main:app
    2018-12-12 20:09:19 default[20181212t094625]  [2018-12-12 20:09:19 +0000] [8145] [INFO] Worker exiting (pid: 8145)
    

    这里是 app.yaml(减去 SendGrid 的环境变量):

    runtime: python37
    env: standard
    #threadsafe: true
    entrypoint: gunicorn --workers 2 --bind :5000 main:app
    
    #runtime_config:
    #  python_version: 3
    
    # This beta setting is necessary for the db hostname parameter to be able to handle a URI in the
    # form “/cloudsql/...” where ... is the instance given here:
    beta_settings:
        cloud_sql_instances: provost-access-148820:us-east1:cuny-courses
    

    【讨论】:

      猜你喜欢
      • 2018-03-29
      • 2018-07-01
      • 2018-03-12
      • 1970-01-01
      • 2016-09-26
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      相关资源
      最近更新 更多