V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Wait845
V2EX  ›  问与答

Python 的 websockets 用的是 async,是不是意味着如果用这个做服务端的话,所有功能都得用 asyncio 写?

  •  
  •   Wait845 · Dec 10, 2021 · 1223 views
    This topic created in 1605 days ago, the information mentioned may be changed or developed.
    4 replies    2021-12-10 17:01:45 +08:00
    ipwx
        1
    ipwx  
       Dec 10, 2021   ❤️ 1
    1. 对于不能 asyncio 的部分你可以用 loop.run_in_executor() 转换到线程池上做,不过……
    2. 很多数据库都有 asyncio 版。比如 aiopg (postgres), aiomysql (mysql), motor (mongodb)
    3. 文件交互可以用 aiofiles ,如果 service static file to http 直接丢给比如 starlette 。
    4. 其实 asyncio 写起来很爽。
    Chichele
        2
    Chichele  
       Dec 10, 2021   ❤️ 1
    vicalloy
        3
    vicalloy  
       Dec 10, 2021   ❤️ 1
    你可以参考一下 https://github.com/zulip/zulip 这个项目。
    websocket 相关操作用 tornado ,web 部分用 django 。
    Buges
        4
    Buges  
       Dec 10, 2021 via Android   ❤️ 1
    python 的 async 和 rust 十分接近,所以用起来比较费劲,但也因而容易控制,只需要把 async 的部分放到 async executor 上跑,其他的还是按同步写就行。
    另外 trio 值得尝试。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2364 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 10:33 · PVG 18:33 · LAX 03:33 · JFK 06:33
    ♥ Do have faith in what you're doing.