简体   繁体   English

Python 无服务器 webapp 与 WSGI 服务器

[英]Python serverless webapp vs WSGI server

I'm developing a web application with Python Flask.我正在用 Python Flask 开发一个 web 应用程序。

I read something about WSGI server and the warning message "WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead."我阅读了一些关于 WSGI 服务器的内容和警告消息“警告:这是一个开发服务器。请勿在生产部署中使用它。请改用生产 WSGI 服务器。”

If I'm using GKE or App Engine or Cloud Ran, is WSGI something I need to learn?如果我使用 GKE 或 App Engine 或 Cloud Ran,我需要学习 WSGI 吗?

TLDR: No, you don't. TLDR:不,你不知道。 You just need to know how to run your App with Flask. Having said that, it doesn't mean that learning/understanding WSGI is a waste but it isn't required.你只需要知道如何使用 Flask 运行你的应用程序。话虽如此,这并不意味着学习/理解 WSGI 是一种浪费,但它不是必需的。

Longer response更长的响应

Gunicorn is a Production WSGI Webserver and this is what Google uses on their Production server to run your Apps for Google App Engine (if your App doesn't contain an entrypoint). Gunicorn是一个生产 WSGI 网络服务器,这是谷歌在他们的生产服务器上用来运行你的谷歌应用引擎应用程序的东西(如果你的应用程序不包含入口点)。 Waitress is another Production WSGI webserver. Waitress是另一个生产 WSGI 网络服务器。

You don't necessarily have to 'learn' how to use any of them or the intricacies of WSGI to be able to build an App.您不一定要“学习”如何使用它们中的任何一个或 WSGI 的复杂性才能构建应用程序。 Learning and understanding how Flask works is good enough学习和理解 Flask 的工作原理就足够了

  1. For Google App Engine对于谷歌应用引擎

    Just build and test your App on your dev environment with Flask (eg run your app with flask run main.py . When you deploy your App to Google App Engine, it will be run with Gunicorn (unless you specified an entrypoint that doesn't use gunicorn)只需使用 Flask 在您的开发环境中构建和测试您的应用程序(例如,使用flask run main.py运行您的应用程序。当您将应用程序部署到 Google App Engine 时,它将使用 Gunicorn 运行(除非您指定了一个入口点,而不是使用枪炮)

    If on the other hand you use dev_appserver.py to run your app locally eg you run your app with dev_appserver.py app.yaml , gcloud CLI will first install gunicorn and then use it to run your App on your local machine.另一方面,如果您使用dev_appserver.py在本地运行您的应用程序,例如您使用dev_appserver.py app.yaml运行您的应用程序,gcloud CLI 将首先安装 gunicorn,然后使用它在本地计算机上运行您的应用程序。

    In both of these instances, you don't have to be an expert on WSGI or gunicorn.在这两种情况下,您不必是 WSGI 或 gunicorn 方面的专家。 Just knowing enough to run your app with Flask is what you need.您只需要知道足以使用 Flask 运行您的应用程序即可。

    However, note that you can't run Python 3 Apps locally with dev_appserver.py on a Windows machine (see google documentation ).但是,请注意,您不能在 Windows 机器上使用dev_appserver.py在本地运行 Python 3 Apps(请参阅谷歌文档)。 I believe it's because gunicorn doesn't run on Windows. But if you still want to use dev_appserver.py for Python 3 Apps on a Windows machine, you can check out a Patch we created (the patch essentially swaps out Gunicorn for Waitress when running your App on your dev machine)我相信这是因为 gunicorn 没有在 Windows 上运行。但是如果你仍然想在 Windows 机器上为 Python 3 个应用程序使用dev_appserver.py ,你可以查看我们创建的 补丁(该补丁在运行时基本上将 Gunicorn 换成了 Waitress你的应用程序在你的开发机器上)

  2. For Cloud Run对于云跑

    You can code and test your App with Flask and then use gunicorn in the container (you don't necessarily have to be an expert or know a lot about gunicorn).您可以使用 Flask 对您的 App 进行编码和测试,然后在容器中使用 gunicorn(您不必是专家或对 gunicorn 了解很多)。 See ' hello world ' sample application from Google请参阅来自 Google 的“ hello world ”示例应用程序

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

相关问题 设计无服务器 function 与常规服务器的差异 - Differences in designing a serverless function vs. regular server Express Amplify Serverless/GraphQL 与 Express 服务器端后端 - Express Amplify Serverless/GraphQL vs Express Server-Side backend Serverless wsgi 应用和aws http api 集成失败 - Serverless wsgi application and aws http api fail to integrate 配置 wsgi python - configure wsgi python 使用无服务器部署 express 时出现内部服务器错误 - internal server error with when deploying express with serverless 在 Serverless Dataproc GCP 中安装 python 包 - Installing python packages in Serverless Dataproc GCP Circle Ci, serverless-framework, serverless-python-requirements - Circle Ci, serverless-framework, serverless-python-requirements Azure webapp:如何更新Python版本? - Azure webapp: How to update Python version? 使用无服务器框架将 Python package 部署到 AWS lambda 时出错 - Error deploying Python package to AWS lambda using Serverless framework “errorMessage”:在 AWS 无服务器上部署时“server.app.use 不是一个函数” - "errorMessage": "server.app.use is not a function" while deploying on AWS serverless
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM