2017-04-20 97 views

回答

0

你可以在另一個線程中運行它(並處理關聯的同步)。或者你可以使它成爲一個協程,並定期向IOLoop屈服(大概是你的代碼的實際版本正在休眠,而不是僅僅是忙碌循環;在這種情況下,你會使用await tornado.gen.sleep()

0

我不知道它是否是最佳答案,但在線程上運行每個循環對我而言運行良好。

import threading 

application.listen(8888) 

event_loop_thread = threading.Thread(target=tornado.ioloop.IOLoop.instance().start) 
event_loop_thread.daemon = True 
event_loop_thread.start() 

custom_loop_thread = threading.Thread(target=custom_loop) 
custom_loop_thread.daemon = True 
custom_loop_thread.start() 

while 1: 
    pass