fghjghf

fghjghf

V2EX member #261862, joined on 2017-10-24 08:46:14 +08:00
  •   You need to sign in to view this topic
    Per fghjghf's settings, the topics list is hidden
    Deals info, including closed deals, is not hidden
    fghjghf's recent replies
    摸鱼度日
    你可以想象做外贸的 v 友是怎样的处境吗?还想涨,直接降,不裁已经算好了,说多了都是泪
    @lolizeppelin 不看我上面的回复吗?张嘴就来???
    @Trim21 但网络 io 的堵塞问题,封装 eopll 的 ioloop 已经帮我们处理了。底层有个队列。socket 非堵塞执行,epollin 和 out 的时候才能寻找对应路由表执行逻辑。EAGAIN 就 modify epoll 的状态,继续执行队列的下一个,如此类推。那就是能走到路由表的 client socket 的网络 io 绝对是可用的。根本不存在堵塞啊。那 tornado 上的 async/await 具体有啥作用呢,不知道我这理解有没有错
    @Trim21 不懂求解。
    from tornado.web import RequestHandler
    from tornado import gen
    import tornado.ioloop

    class IndexHandler(RequestHandler):
    def get(self):
    self.write('this is index')

    class BlockingHandler(RequestHandler):
    async def get(self):
    result = await self.dosomething()
    self.write(result)

    async def dosomething(self):
    # 如果是其他处理函数或者逻辑,要保证函数是协程
    await gen.sleep(20)
    return 'block end'

    app = tornado.web.Application([
    (r"/index", IndexHandler),
    (r"/blocking", BlockingHandler)
    ])
    if __name__ == "__main__":
    app.listen(80)
    tornado.ioloop.IOLoop.instance().start()

    那 async/await 用在 tornado6 上有啥作用呢?一定要 asyncio 内包装的函数才有效。但 IOLoop 已经用 epoll 实现网络 io 复用了。实际应用中,堵塞的不都是磁盘 io 么。那这么做的目的又是啥呢
    @lniwn 不懂求解。那就是说,必须是 asyncio 包内封装的函数,例如 asyncio.sleep(3)这种才有用吗?(我也测过,asyncio.sleep 函数的确有效,会快很多,但这不是真的 io 操作啊)。那遇到真的 io 操作如何是好?其实我是想和 tornado 搭配用的。tornado6 不支持 @gen.coroutine 了,必须用 async/await 。我的理解 ioloop 是通过 epoll 的 in out error 非堵塞做到单线程高并发的,遇到 EAGAIN 就用协程继续执行另一段逻辑。不知道这样理解是否有错
    Mar 19, 2020
    Replied to a topic by fghjghf iOS 求 iOS 大佬,这种功能需要如何实现
    @chipmuck 已解决,感谢
    @ty89 说得非常正确,运气占了很大部分
    Mar 10, 2020
    Replied to a topic by chris9 上海 v2er 们,有股票交流群么
    我已经亏到不想说。 这段时间,亏了 1 个月工资
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   992 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 12ms · UTC 19:08 · PVG 03:08 · LAX 12:08 · JFK 15:08
    ♥ Do have faith in what you're doing.