我正在尝试使用协程来向NATS发送数据(纳齐奥消息系统)。你知道吗
当我尝试在没有参数和for循环的情况下调用这段代码时,它工作得非常好。你知道吗
但当我添加参数时,会产生数控连接函数不会返回任何内容并继续执行主函数。你知道吗
如何调用任何带有参数的协同程序?你知道吗
@tornado.gen.coroutine
def process_events_list(events):
try:
nc = NATS()
parser = SafeConfigParser()
conf = os.path.realpath(
os.path.join(os.getcwd(),'ev_nats\\ev_nats.ini'))
parser.read(conf)
endpoints = ast.literal_eval(parser.get('Nats', 'Servers'))
subject = parser.get('Nats', 'Subject')
opts = {"servers": endpoints}
**yield nc.connect(**opts)** # wont connect return to main
for ev in events:
yield nc.publish(subject, ev)
yield nc.flush()
log("Published")
except Exception, e:
log(e)
if __name__=='__main__': # if run directly, not called by event_dispatcher.py
evt = ['1','2','3']
tornado.ioloop.IOLoop.instance().run_sync(lambda : process_events_list(evt))
我将尝试进一步调试传递给服务器的端点列表是否有效。否则,如果您可以连接到服务器,那么这样做应该是可行的。你知道吗
相关问题 更多 >
编程相关推荐