自定义服务器 python 的 asyncio 与 asyncore

dsa*_*389 3 python asyncsocket asyncore python-asyncio

我想为某个项目构建一个自定义服务器,但我不知道和服务器之间有什么区别,什么更好用,以及为什么asyncoreasyncio

小智 5

asyncore是执行一些基本事件驱动服务器和客户端的“旧”Python 2 方法(换句话说,用于执行异步 IO)。

asyncio是新的 Python 3 模块,它提供了用于一般异步 IO 的完整框架。它具有更多功能,包括对协程的支持,允许您使用 和 等关键字async defawait从而提高异步代码的可读性。

总而言之,asyncio就是要走的路。 asyncore不建议在 Python 3 中使用,新项目应该使用 Python 3,而不是 Python 2。如果您坚持使用 Python 2,这asyncore是一个明智的选择。