Twisted transport.write

后端 未结 4 460
心在旅途
心在旅途 2021-01-18 12:55

Is there any way to force self.transport.write(response) to write immediately to its connection so that the next call to self.transport.write(response) does not get buffere

4条回答
  •  自闭症患者
    2021-01-18 13:29

    Maybe You can register your protocol as a pull producer to the transport

    self.transport.registerProducer(self, False)
    

    and then create a write method in your protocol that has it's job buffering the data until the transport call your protocol resumeProducing method to fetch the data one by one.

    def write(self, data):
        self._buffers.append(data)
    
    def resumeProducing(self):
        data = self._buffers.pop()
        self.transport.write(data)
    

提交回复
热议问题