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
fyooo
V2EX  ›  Python

2018 年 python2.7+ tornado 连 mysql 的最佳实践是啥?

  •  
  •   fyooo · 2018-05-29 21:11:23 +08:00 · 3945 次点击
    这是一个创建于 2149 天前的主题,其中的信息可能已经有所发展或是发生改变。
    torndb 不维护了 ( https://github.com/bdarnell/torndb)

    peewee-async 只支持 Python 3.4+ ( http://peewee-async.readthedocs.io/en/latest/)

    AsyncTorndb 也是 4 年前的代码 了 ( https://github.com/mayflaver/AsyncTorndb)
    11 条回复    2018-06-03 23:36:38 +08:00
    ericls
        1
    ericls  
       2018-05-29 21:13:17 +08:00 via iPhone   ❤️ 1
    run in executor
    phithon
        2
    phithon  
       2018-05-29 21:52:05 +08:00
    古代的东西配古代的库,应该不会出什么 BUG 吧,就用 torndb 呗。
    chenqh
        3
    chenqh  
       2018-05-29 22:13:30 +08:00
    感觉 tornado 已经死了,关键是 py3 的异步 web 框架不知道选哪个好,郁闷
    mywaiting
        4
    mywaiting  
       2018-05-29 22:45:27 +08:00   ❤️ 1
    就用 torndb 没啥事的,不过也就别想着异步啥啥啥就可以了

    感觉 py3 的异步已经快要成为 js callback 那样了,遍地都是 async,看得心烦

    最近有些项目用到了 Nginx + Lua/njs 特别是 lua,从此告别各种异步的概念,一股脑丢 nginx 自己搞,而且在 nginx 强大的架构下,从此告别各种语言论战下的性能问题,毕竟 Nginx + lua 几乎是等同于在写纯 C 的性能了,在单纯 web 应用下的架构,我觉得没有什么比这个的性能更高的了

    @chenqh 懂 flask 的话,投奔 aiohttp 去不会错,在 uvloop 的强大的续命技能下,领跑个三五年没问题
    zsj950618
        5
    zsj950618  
       2018-05-30 00:55:30 +08:00
    首先都 8102 年了,怎么还是 python 2 ??
    alphadog619
        6
    alphadog619  
       2018-05-30 09:08:31 +08:00
    Sanic 了解一下?
    fyooo
        7
    fyooo  
    OP
       2018-05-30 10:26:43 +08:00
    @zsj950618 接手前人的项目,python2 和 3 我没得选

    @alphadog619 sanic 也是基于 python3 的吧,而前人项目是 python2+tornado 的
    myyou
        8
    myyou  
       2018-05-30 11:03:23 +08:00
    @fyooo 逐渐替换,新代码写在新项目中,老项目还维持运转,以后逐渐迁移老项目
    bnm965321
        9
    bnm965321  
       2018-05-30 12:54:51 +08:00
    tornado5.0 默认使用 asyncio eventloop,可以使用 asyncio 的一切异步库
    fyooo
        10
    fyooo  
    OP
       2018-05-30 14:52:38 +08:00
    @bnm965321

    貌似不行吧,根据官方指引: http://peewee-async.readthedocs.io/en/latest/peewee_async/tornado.html

    ```
    async def post(self):
    name = self.get_argument('name')
    obj = await self.application.objects.create(TestNameModel, name=name)
    ```

    里面的 `async`, `await` 都是 python3 的语法
    bnm965321
        11
    bnm965321  
       2018-06-03 23:36:38 +08:00
    @fyooo 对,我没注意到你还在用 python2
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3134 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 14:44 · PVG 22:44 · LAX 07:44 · JFK 10:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.