推荐学习书目
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
larkifly
V2EX  ›  Python

webpy 如何和 twisted 结合,实现异步返回。

  •  
  •   larkifly · Oct 30, 2015 · 3424 views
    This topic created in 3873 days ago, the information mentioned may be changed or developed.

    正常 webpy 是这个样,

    class a:

    POST(self):

    return 'hello world'

    我想实现这个样子

    class a:

    def POST(self):

    b(....)

    在函数 b 里面返回给客户端

    8 replies    2015-11-02 10:26:44 +08:00
    likebeta
        1
    likebeta  
       Oct 30, 2015
    好奇特的组合, 要用 twisted 就表示你要用 twisted 的 reactor
    Karblue
        2
    Karblue  
       Oct 30, 2015 via Android
    试试 tornado 吧, webpy 不清楚有没有自带的异步,和 tw 组合起来写法应该很蛋疼
    tempdban
        3
    tempdban  
       Oct 30, 2015 via Android
    什么叫异步返回?既然都返回了连接都断掉了你还怎么返回?
    mathgl
        4
    mathgl  
       Oct 31, 2015
    felixzhu
        5
    felixzhu  
       Oct 31, 2015
    为啥不用 tornado 。。
    cheng007
        6
    cheng007  
       Oct 31, 2015
    异步代码写起来真的是坑死啊,你要事觉着 webpy 不够快,加上 gevent 啊
    jamiesun
        7
    jamiesun  
       Oct 31, 2015
    @larkifly 我的情况和你差不多,我的项目深度使用 twisted ,一开始我使用了 bottle ,也遇到异步调用的麻烦,在 twisted 的支持下,使用异步是可行的,只不过比较麻烦,我在实现的半路中就放弃了。

    但是因为必须使用 twisted ,所以就改用了基于 twisted 的 web 框架 cyclone , https://github.com/fiorix/cyclone ,这个框架 fork 自 tornado ,活跃度非常高,用过 tornado 框架的迁移无任何障碍,而且异步调用,协程等一应俱全。

    异步代码没什么坑不坑死的,只要框架无太多 BUG ,你的应用程序结构合理,再加上仔细认真,没有什么好担心的。
    larkifly
        8
    larkifly  
    OP
       Nov 2, 2015
    @felixzhu 不让用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2680 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 10:26 · PVG 18:26 · LAX 03:26 · JFK 06:26
    ♥ Do have faith in what you're doing.