不知道为什么这不起作用,我想子类化消息并添加其他行为:
import data_pb2 as pb2
class Status(pb2.Status):
def __init__(self, streamer, *args, **kwargs):
super().__init__(*args, **kwargs)
self.streamer = streamer
def __setattr__(self, key, value):
super().__setattr__(key, value)
self.streamer.send_update()
当有人更改 pb2.Status 消息时,我希望调用 send_update。这是我收到的无用错误消息:
Traceback (most recent call last):
File "server.py", line 62, in <module>
class Status(pb2.Status):
File "C:\AppData\Local\conda\conda\envs\lib\site-packages\google\protobuf\internal\python_message.py", line 126, in __new__
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
KeyError: 'DESCRIPTOR'