【发布时间】:2018-10-14 17:31:53
【问题描述】:
我有以下代码,它在 Tornado = 5 运行它就会失败,
import tornado.httpserver
import tornado.ioloop
import threading
import tornado.web,tornado.websocket
class thr(threading.Thread):
def __init__(self,handler):
self.handler=handler
threading.Thread.__init__(self)
def run(self):
self.handler.write_message("test")
class ClientWebSocketConnectionHandler(tornado.websocket.WebSocketHandler):
def open(self):
print ("opened")
def on_message(self, message):
thr(self).start()
class MainApplication(tornado.web.Application):
def __init__(self):
handlers = [(r'/User', ClientWebSocketConnectionHandler),]
tornado.web.Application.__init__(self, handlers,)
TheShieldsWebSocket = MainApplication()
server = tornado.httpserver.HTTPServer(TheShieldsWebSocket)
server.listen(8085,'0.0.0.0')
tornado.ioloop.IOLoop.instance().start()
错误说:RuntimeError: There is no current event loop in thread 'Thread-1'
这到底是怎么回事?好像跟线程有关。
【问题讨论】:
-
你的 Python 是哪个版本的?
-
我使用 python 3.6。我听说
async,但我不知道必须 -
我可以在
Python 2.x上运行你的代码,还没有尝试Python 3.x。 -
你的龙卷风版本是多少?
-
'4.5.2',但我想这与龙卷风无关,这是
threading问题。