sanic-org/sanic

The AsyncIO Server should use Python's 3.7 BufferedProtocol when possible ?

开放

#1,873 创建于 2020年6月15日

 (8 条评论) (0 个反应) (0 位负责人)Python (1,515 个派生)batch import
feature requesthelp wantedidea discussionneeds investigation

仓库指标

星标
 (17,623 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Not sure how much performance it can add, but might be worth exploring: https://bugs.python.org/issue32251

It can be done in a backward compatible way with Python 3.6 like this: https://github.com/huge-success/sanic/blob/bedf68a9b2025618a94cb8044f495a0abd87a134/sanic/server.py#L47

Instead of inheriting asyncio.Protocol, it can be done:

try:
    from asyncio import BufferedProtocol as BaseProtocol
# Python 3.6 support
except ImportError:
    from asyncio import Protocol as BaseProtocol

And inside the implementation, it can be written for both Python 3.6 and 3.7+ by defining the 3 methods (where the first 2 use a preallocated buffer):

class HttpProtocol(BaseProtocol):
    def get_buffer(self, sizehint):
    def buffer_updated(self, nbytes):
    # Python 3.6 support
    def data_received(self, data):

贡献者指南