11

据我所知

  1. wsgiref - 没有代码重新加载
  2. CherryPy - 不仅仅是服务器
  3. mod_wsgi - 所有 apache 开销
  4. paste.httpserver - paste 是一个巨大的包,里面有其他东西
  5. flup - 和 paste 一样,东西太多了。
  6. 产卵 - 从未使用过,但看起来足够轻巧。
  7. Tornado - 不是真正的 wsgi + 完整的“框架”
  8. Werkzeug - 运行命令

还有其他人吗?你更喜欢哪一个?

4

7 回答 7

5

您可能想看看Werkzeug - 它是一个 WSGI 实用工具包。它包括一个 runserver 函数,该函数接受 wsgiref 服务器并添加自动代码重新加载(您也可以将其配置为在配置文件更改时重新加载)和一个很棒的调试器。

附带说明一下,您对框架的蔑视听起来像是您打算从头开始处理所有 WSGI 内容,在这种情况下,我建议您使用 Werkzeug 的实用程序函数来处理解析请求和生成响应。这比自己做要有趣得多。(为了 Guido 的爱,请不要使用cgi.FieldStorage!)

于 2010-01-29T12:32:13.120 回答
4

查看 werkzeug 的 run_simple:

http://werkzeug.pocoo.org/documentation/0.5.1/serving.html

除了为您提供自动代码重新加载之外,您还可以使用 use_debugger=True 在您的应用程序顶部包含他们漂亮的调试器(在回溯的每一行中都包括控制台)。

于 2010-02-13T20:07:44.517 回答
2

One really easy way is CGI (together with a regular web server, and using wsgiref.handlers.CGIHandler). Terrible for performance on a production server, but great for development. You can write a single script that works as both a mod_wsgi WSGIScriptAlias (exposing an application object), and as a mod_cgi ScriptAlias (calling wsgiref when __name__=='__main__').

Many WSGI environments have a way to reload the basic script, for example mod_wsgi's WSGIScriptReloading, which is on by default. Unfortunately, you're likely to be putting much of your code in modules, which isn't so easy to reload. In mod_wsgi you can also do it by sending a SIGINT to perform a reload when in daemon mode. Unfortunately you still have to sniff every module you're using for mtime updates in order to know whether you have to reload. And it doesn't work in embedded mode.

A messy but feasible approach is to sniff all modules that are part of your application, and if any have been updated since the last check, reload them all. You have to reload them at once, by removing them all from the sys.modules lookup (remove None-valued entries too whilst you're there, to avoid relative import lookup problems), in order to ensure they don't keep cross-references to the old versions of themselves. And of course they must not leave other references to themselves outside of your application. You can see an example of this in action in the ModuleUpdater class here.

(This software isn't ready for release, but has been providing module reloading for my WSGI apps for a few years and seems to be stable. The idea is to put all your WSGI app in an application class in a package, which you can import from a single WSGI/CGI/command-line entry point script; you include the deployment config in that script.)

于 2010-01-29T12:57:53.420 回答
1

到目前为止,我一直在使用 CherryPy,与 Django(虽然不在您的列表中,但它是我使用的唯一其他开发服务器)相比,我更喜欢它。它按照所说的去做:它只在你需要它的时候出现,并且在剩下的时间里不碍事。

使用 Django 似乎我需要订阅 Django 的做事方式。尽管 Django 提供了更多开箱即用的功能(默认管理界面、网页上的小部件),但使用 CherryPy 似乎只是另一个具有非常好的(通常让您惊讶)功能的导入。

于 2010-01-29T12:33:35.723 回答
1

我推荐粘贴或 CherryPy。它们是最容易启动和运行的。

于 2010-01-29T12:52:37.473 回答
1

此外,您还错过了 web.py,它既小又支持代码重载。

于 2010-02-16T03:36:47.017 回答
0

除了其他粘贴模块,您可以将 paste.reloader 与任何 wsgi-server 一起使用。

# 运行粘贴重新加载器
导入 paste.reloader 作为重新加载器
reloader.install()

# 运行 wsgiref 服务器
从 wsgiref 导入 simple_server
simple_server.make_server('', 8080, main_wsgi_app).serve_forever()

够简约吗?

于 2010-02-16T03:30:16.140 回答