import gnsq
class something():
def __init__(self,pb=None,pk=None,address=None):
self.pb = pb
self.pk = pk
self.address = address
def connect(self):
consumer = gnsq.Consumer(self.pb,'ch',self.address)
@consumer.on_message.connect
def response_handler(consumer,msg):
return msg.body
consumer.start()
我将如何获得response_handler
的返回值,因此,我将能够传递给父函数connect()
,因此当我调用它时,它将返回返回的值。 message.body
来自子功能。
我会想到以下内容:
import gnsq
class something():
def __init__(self,msg):
return msg.body
consumer.start()
return response_handler
nsq = something('pb','pk','address')
# should print whatever message.body is
print nsq.connect()
但是它不起作用。注意:consumer.start()
正在阻止