我正在使用 pubsub 库向某些主题发布消息:
# init publisher
publisher = pubsub_v1.PublisherClient(credentials=credentials)
# publish iteratively and keep track of the original iter id
for iter in [0,1,2,3,4]:
message_future = self.publisher.publish(topic_path)
message_future.add_done_callback(callback)
# callback
def callback(message_future):
print(message_future)
# how can I capture here the original "iter"?
但是,我想添加一些元数据,例如:
message_future.add_done_callback(callback(message_future, iter=iter))
虽然这有效,但我在函数完成错误后收到:
TypeError:“NoneType”对象在 add_done_callback 中的第 149 行不可调用
怎么了?
另请参阅: https ://googleapis.dev/python/pubsub/latest/publisher/index.html