sanic-org/sanic

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

オープン

#1,873 opened on 2020/06/15

 (8 件のコメント) (0 件のリアクション) (0 人の担当者)Python (1,515 件のフォーク)batch import
feature requesthelp wantedidea discussionneeds investigation

Repository metrics

Stars
 (17,623 個のスター)
PR merge metrics
 (30d に merged 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):

コントリビューターガイド