我有一个运行django应用程序的龙卷风服务器。 我有一个问号驱动程序,可以连接到正在运行的大多数服务器。
我正在尝试使两者一起工作,但从另一个开始。 我尝试对一个进程进行线程处理并得到“ RuntimeError:线程'Thread-1'中没有当前事件循环”
def main():
wsgi_app = tornado.wsgi.WSGIContainer(
django.core.handlers.wsgi.WSGIHandler())
tornado_app = tornado.web.Application(
[
(r'/static/(.*)', NoCacheStaticHandler, {'path': 'static'}),
('/hello-tornado', HelloHandler),
('/websocket', WebSocketHandler),
('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
])
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(options.port)
instance = tornado.ioloop.IOLoop.instance()
p = threading.Thread(target=mattermost_chat,args=(instance,))
p.start()
instance.start()
def mattermost_chat(parameter):
print(parameter)
chat = Chat()
chat.login()
chat.connect()
if __name__ == '__main__':
#mattermost_chat()
main()
示例运行。
(env-bd2l-csmu-int-app01-python-3) csmu@int-app01:~/bd2l-django$ ./tornado-server.py
Loading environment
/home/csmu/bd2l-django/api/settings.py
/home/csmu/bd2l-django/api/.env
<tornado.platform.asyncio.AsyncIOMainLoop object at 0x7f5fb9631080>
{'scheme': 'http', 'url': 'localhost', 'token': '8ttjc63cdbr58y6jr7huj75q3a', 'port': 8065}
{'last_name': 'Processor', 'timezone': {'useAutomaticTimezone': 'true', 'manualTimezone': '', 'automaticTimezone': ''}, 'position': '', 'username': 'bd2l-processor', 'create_at': 1533167906430, 'notify_props': {'push_status': 'away', 'mention_keys': 'bd2l-processor,@bd2l-processor', 'desktop_sound': 'true', 'desktop': 'mention', 'email': 'true', 'comments': 'never', 'channel': 'true', 'first_name': 'false', 'push': 'mention'}, 'roles': 'system_user system_user_access_token', 'update_at': 1533169925778, 'auth_service': '', 'last_password_update': 1533167906430, 'id': 'duicxyoipbg7tkegjh1sro6ndo', 'nickname': '', 'delete_at': 0, 'email': 'bd2l-processor@bd2l.com.au', 'locale': 'en', 'first_name': 'Mipgen', 'auth_data': ''}
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "./tornado-server.py", line 247, in mattermost_chat
chat.connect()
File "./tornado-server.py", line 200, in connect
self._websocket = self.driver.init_websocket(mattermost_event_handler)
File "/home/csmu/bd2l-django/env-bd2l-csmu-int-app01-python-3/lib/python3.5/site-packages/mattermostdriver/driver.py", line 136, in init_websocket
loop = asyncio.get_event_loop()
File "/usr/lib/python3.5/asyncio/events.py", line 632, in get_event_loop
return get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.5/asyncio/events.py", line 578, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-1'.
如何使用龙卷风服务器运行额外的线程?