有人能给我一个关于 WSGI 幕后细节与其他 Python Web 界面方法的高级技术概述吗?
首先:
- 我了解什么是 WSGI 以及如何使用它
- 我了解什么是“其他”方法(Apache mod-python、fcgi 等)以及如何使用它们
- 我了解它们的实际差异 我了解
什么 不明白 与 UWSGI 之类的方法相比,每种“其他”方法在幕后是如何工作的。您的服务器(Nginx 等)是否将请求路由到 WSGI 应用程序,并且 UWSGI 是否为路由到它的每个请求创建一个新的 Python 解释器? WSGI 与其他更传统/猴子修补的方法有多大不同(除了 WSGI 提供的不同的、更简单的 Python 接口)?我错过了什么灵光一现的时刻?
Firstly:
- I understand what WSGI is and how to use it
- I understand what "other" methods (Apache mod-python, fcgi, et al) are, and how to use them
- I understand their practical differences
What I don't understand is how each of the various "other" methods work compared to something like UWSGI, behind the scenes. Does your server (Nginx, etc) route the request to your WSGI application and UWSGI creates a new Python interpreter for each request routed to it? How much different is is from the other more traditional / monkey patched methods is WSGI (aside from the different, easier Python interface that WSGI offers)? What light bulb moment am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了 CGI 之外,几乎不会根据请求创建新的 Python 解释器。阅读:
http://blog。 dscpl.com.au/2009/03/python-interpreter-is-not-created-for.html
这是针对 mod_python 编写的,但也适用于 mod_wsgi 和任何使用持久进程的 WSGI 托管机制。
另请阅读:
http://www.python.org/dev/ peps/pep-0333/#environ-variables
在那里您会找到描述的“wsgi.run_once”变量。这用于向 WSGI 应用程序指示何时使用托管机制,该机制将看到进程仅处理一个请求然后退出,即 CGI。因此,编写一个测试 hello world 应用程序,该应用程序转储 WSGI 环境,并查看它针对您所使用的设置。
另请注意“wsgi.multiprocess”和“wsgi.multithread”变量。它们告诉您是否正在使用多进程服务器,以便您的应用程序有多个实例同时处理请求。 “wsgi.multithread”变量告诉您进程本身是否正在同一进程中的并发线程中处理多个请求。
有关与 Apache 嵌入式系统相关的多进程和多线程模型(例如 mod_python 和 mod_wsgi 以及 mod_wsgi 守护进程模式)的更多信息,请参阅:
http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading
Except for CGI, a new Python interpreter is nearly never created per request. Read:
http://blog.dscpl.com.au/2009/03/python-interpreter-is-not-created-for.html
This was written in respect of mod_python but also applies to mod_wsgi and any WSGI hosting mechanism that uses persistent processes.
Also read:
http://www.python.org/dev/peps/pep-0333/#environ-variables
There you will find described the 'wsgi.run_once' variable described. This is used to indicate to a WSGI application when a hosting mechanism is used which would see a process only handling one request and then being exited, ie., CGI. Thus, write a test hello world application which dumps out the WSGI environment and see what it is set to for what you are using.
Also pay attention to the 'wsgi.multiprocess' and 'wsgi.multithread' variables. They tell you if a multi process server is being used such that there are multiple instances of your application handling requests at the same time. The 'wsgi.multithread' variable tells you if the process itself is handling multiple requests in concurrent threads in same process.
For more on multiprocess and multithread models in relation to Apache embedded systems, such as mod_python and mod_wsgi, and mod_wsgi daemon mode, see:
http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading