Gunicorn worker for Sanic

2017-03-20 18:46:12 +08:00
 messense

https://github.com/messense/sanic-gunicorn

也给官方发了一个 PR: https://github.com/channelcat/sanic/pull/545

3273 次点击
所在节点    Python
10 条回复
cheetah
2017-03-20 18:54:44 +08:00
弱弱的问一句, Gunicorn 自带的 AiohttpWorker 不能运行 sanic?
est
2017-03-20 19:04:12 +08:00
66666
messense
2017-03-20 19:27:58 +08:00
@cheetah 好像 aiohttp 的速度不够快啊,不过我也没试……待验证。
messense
2017-03-20 20:15:07 +08:00
@cheetah 根本起不来

gunicorn simple_server:app --bind localhost:8000 --worker-class gaiohttp --capture-output
[2017-03-20 20:13:34 +0800] [3226] [INFO] Starting gunicorn 19.6.0
[2017-03-20 20:13:34 +0800] [3226] [INFO] Listening at: http://127.0.0.1:8000 (3226)
[2017-03-20 20:13:34 +0800] [3226] [INFO] Using worker: gaiohttp
[2017-03-20 20:13:34 +0800] [3260] [INFO] Booting worker with pid: 3260
Application object must be callable.
[2017-03-20 20:13:34 +0800] [3260] [INFO] Worker exiting (pid: 3260)
[2017-03-20 20:13:34 +0800] [3226] [INFO] Shutting down: Master
[2017-03-20 20:13:34 +0800] [3226] [INFO] Reason: App failed to load.

也需要一些 hack ,比如类似: https://github.com/messense/sanic-gunicorn/commit/e60a683f976cd66a36f3c1ee88b92f4be190067a#diff-757823b0d65a4f88a48899c3fd4135c8R54

或者自己实现下 __call__
messense
2017-03-20 20:18:16 +08:00
@cheetah #4 actually ,即便实现了 __call__ 也不好继续下去,因为 Sanic 并不兼容 WSGI , gunicorn 的 gaiohttp worker 是基于 WSGI 的
messense
2017-03-20 20:26:41 +08:00
@cheetah aiohttp 2.0 也废弃了 WSGI 支持,估计以后 gaiohttp 也没法用了。

http://aiohttp.readthedocs.io/en/latest/migration.html#wsgi
freestyle
2017-03-20 23:11:27 +08:00
问一下 sanic 跑同步的 wsgi 不会浪费性能吗
messense
2017-03-21 10:51:30 +08:00
@freestyle #7 并不是同步跑 WSGI ,自定义 gunicorn worker 跑 asyncio event loop
guyskk
2017-03-21 21:58:43 +08:00
ORM 支持怎么样了?楼主有打算在生产环境用 sanic 吗?
messense
2017-03-22 21:12:13 +08:00
@guyskk #9 ORM 支持不咋的,有在生产环境使用,一个并不涉及到数据库的项目:

https://github.com/bosondata/prerender

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/348916

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX