V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
messense
V2EX  ›  Python

Gunicorn worker for Sanic

  •  
  •   messense ·
    messense · 2017-03-20 18:46:12 +08:00 · 3262 次点击
    这是一个创建于 2565 天前的主题,其中的信息可能已经有所发展或是发生改变。
    10 条回复    2017-03-22 21:12:13 +08:00
    cheetah
        1
    cheetah  
       2017-03-20 18:54:44 +08:00
    弱弱的问一句, Gunicorn 自带的 AiohttpWorker 不能运行 sanic?
    est
        2
    est  
       2017-03-20 19:04:12 +08:00
    66666
    messense
        3
    messense  
    OP
       2017-03-20 19:27:58 +08:00 via iPhone
    @cheetah 好像 aiohttp 的速度不够快啊,不过我也没试……待验证。
    messense
        4
    messense  
    OP
       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
        5
    messense  
    OP
       2017-03-20 20:18:16 +08:00
    @cheetah #4 actually ,即便实现了 __call__ 也不好继续下去,因为 Sanic 并不兼容 WSGI , gunicorn 的 gaiohttp worker 是基于 WSGI 的
    messense
        6
    messense  
    OP
       2017-03-20 20:26:41 +08:00
    @cheetah aiohttp 2.0 也废弃了 WSGI 支持,估计以后 gaiohttp 也没法用了。

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

    https://github.com/bosondata/prerender
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5390 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:36 · PVG 16:36 · LAX 01:36 · JFK 04:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.