Python 使用twisted/asyncio的缓冲区应用程序

Python 使用twisted/asyncio的缓冲区应用程序,python,python-3.x,twisted,python-asyncio,Python,Python 3.x,Twisted,Python Asyncio,我有一个简单的应用程序,它接收数据,并且必须批量将数据推送到另一个服务 如何使用twisted或asyncio实现它 目前,我有下一个使用twisted的代码: from twisted.internet import protocol, reactor, endpoints from twisted.protocols import basic class FirehoseProtocol(basic.LineReceiver): def __init__(self):

我有一个简单的应用程序,它接收数据,并且必须批量将数据推送到另一个服务

如何使用twisted或asyncio实现它

目前,我有下一个使用twisted的代码:

from twisted.internet import protocol, reactor, endpoints
from twisted.protocols import basic


class FirehoseProtocol(basic.LineReceiver):
    def __init__(self):
        self.data = []

    def lineReceived(self, line):
        self.data.append(line)

    def push_to_firehose(self):
        pass  # TODO


class EchoFactory(protocol.ServerFactory):
    protocol = FirehoseProtocol


endpoints.serverFromString(reactor, "tcp:5001").listen(EchoFactory())

reactor.run()

你没有说什么定义了批次。如果我们假设多行定义了一个批次:

def lineReceived(self, line):
    self.data.append(line)
    if len(self.data) == batch_size:
        self.push_to_firehose()

你没有说什么定义了批次。如果我们假设多行定义了一个批次:

def lineReceived(self, line):
    self.data.append(line)
    if len(self.data) == batch_size:
        self.push_to_firehose()

确切地说,批处理意味着N行,其中N是动态的,将根据行大小进行计算。但我假设它将阻止接收新行,对吗?该应用程序需要相当高的负载,因此它必须每秒至少提供300条记录。你认为什么会阻止它?Twisted中的API不会阻塞。这就是Twisted的要点。确切地说,batch意味着N行,其中N是动态的,将根据行大小进行计算。但我假设它将阻止接收新行,对吗?该应用程序需要相当高的负载,因此它必须每秒至少提供300条记录。你认为什么会阻止它?Twisted中的API不会阻塞。这就是扭曲的重点。