I'm trying to use coroutine in order to send data to NATS (nats.io messaging system).
When I try to call this code without arguments and for loop it's working perfectly.
But when I am adding arguments, the yield nc.connect function wouldn't return anything and continue to main function.
How can I call any coroutine with arguments?
@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))