refresh()可以从main()调用,另一方面,refreshloop()看起来不会启动。我希望refreshloop()定期调用refresh()。我在这里做错了什么?
count = 0
mainloop = tornado.ioloop.IOLoop.instance()
stoprloop = False
@gen.coroutine
def refreshloop(interval):
global mainloop
count += 1
print "here #" + str(count)
next_time = mainloop.current().time()
while (stoprloop == False):
next_time += int(interval)
refresh()
while next_time <= mainloop.current().time():
next_time += int(interval)
yield gen.Task(mainloop.current().call_at, next_time)
def main():
global mainloop
...
refresh()
refreshloop(5)
mainloop.start()
if __name__ == '__main__':
main()
____编辑_____________________________________________________________________
谢谢你们俩!
导入的脚本仅在本地可用,并且未显示结果错误。
____编辑_____________________________________________________________________
这两种解决方案似乎都很完美:)。
refreshloop(5)
mainloop.add_callback(refreshloop, 5)
答案 0 :(得分:0)
您无法直接调用协同程序,您需要将其添加为callback to ioloop:
def main():
global mainloop
...
refresh()
mainloop.add_callback(refreshloop, 5)
mainloop.start()