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

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

  •  
  •   larkifly · 2015-10-30 17:56:54 +08:00 · 2905 次点击
    这是一个创建于 3111 天前的主题,其中的信息可能已经有所发展或是发生改变。

    正常 webpy 是这个样,

    class a:

    POST(self):

    return 'hello world'

    我想实现这个样子

    class a:

    def POST(self):

    b(....)

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

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

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

    异步代码没什么坑不坑死的,只要框架无太多 BUG ,你的应用程序结构合理,再加上仔细认真,没有什么好担心的。
    larkifly
        8
    larkifly  
    OP
       2015-11-02 10:26:44 +08:00
    @felixzhu 不让用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   6094 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 06:11 · PVG 14:11 · LAX 23:11 · JFK 02:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.