我想要的只是在一个线程中运行一个 ioloop,然后将消息写入 nsqd。这是一个尝试:
#!/usr/bin/env python2
# coding=utf-8
import tornado
import time
from nsq.writer import Writer
w = Writer(["bj1:4150", "bj2:4150"], reconnect_interval=15)
w.connect()
@tornado.gen.coroutine
def future_pub(topic, msg):
result = w.pub(topic, msg)
print(result)
time.sleep(3)
raise tornado.gen.Return(result)
@tornado.gen.coroutine
def main():
while True:
try:
future = future_pub("test", "message")
yield future
except Exception as e:
print(e.message)
tornado.ioloop.IOLoop.instance().run_sync(main)
但它没有用。你可以帮帮我吗?谢谢!