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

2021 年 12 月 10 日
 Wait845
1190 次点击
所在节点    问与答
4 条回复
ipwx
2021 年 12 月 10 日
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
2021 年 12 月 10 日
vicalloy
2021 年 12 月 10 日
你可以参考一下 https://github.com/zulip/zulip 这个项目。
websocket 相关操作用 tornado ,web 部分用 django 。
Buges
2021 年 12 月 10 日
python 的 async 和 rust 十分接近,所以用起来比较费劲,但也因而容易控制,只需要把 async 的部分放到 async executor 上跑,其他的还是按同步写就行。
另外 trio 值得尝试。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/821375

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX