Commit 20c7b2db authored by ibuler's avatar ibuler

[Update] 使用eventlet, websocket支持

parent f3df8adb
...@@ -218,9 +218,11 @@ class Coco: ...@@ -218,9 +218,11 @@ class Coco:
self.run_httpd() self.run_httpd()
signal.signal(signal.SIGTERM, lambda x, y: self.shutdown()) signal.signal(signal.SIGTERM, lambda x, y: self.shutdown())
while self.stop_evt.wait(5): while True:
if self.stop_evt.is_set():
print("Coco receive term signal, exit") print("Coco receive term signal, exit")
break break
time.sleep(3)
except KeyboardInterrupt: except KeyboardInterrupt:
self.stop_evt.set() self.stop_evt.set()
self.shutdown() self.shutdown()
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import os import os
import socket import socket
import uuid import uuid
import eventlet
from flask_socketio import SocketIO, Namespace, join_room from flask_socketio import SocketIO, Namespace, join_room
from flask import Flask, request, current_app, redirect from flask import Flask, request, current_app, redirect
...@@ -16,6 +17,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) ...@@ -16,6 +17,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
logger = get_logger(__file__) logger = get_logger(__file__)
eventlet.monkey_patch()
class BaseNamespace(Namespace): class BaseNamespace(Namespace):
current_user = None current_user = None
...@@ -23,7 +26,7 @@ class BaseNamespace(Namespace): ...@@ -23,7 +26,7 @@ class BaseNamespace(Namespace):
def on_connect(self): def on_connect(self):
self.current_user = self.get_current_user() self.current_user = self.get_current_user()
if self.current_user is None: if self.current_user is None:
return redirect(current_app.config['LOGIN_URL']) return redirect(self.socketio.config['LOGIN_URL'])
logger.debug("{} connect websocket".format(self.current_user)) logger.debug("{} connect websocket".format(self.current_user))
def get_current_user(self): def get_current_user(self):
...@@ -236,8 +239,8 @@ class HttpServer: ...@@ -236,8 +239,8 @@ class HttpServer:
'LOGIN_URL': '/login' 'LOGIN_URL': '/login'
} }
init_kwargs = dict( init_kwargs = dict(
# async_mode="gevent", async_mode="eventlet",
async_mode="threading", # async_mode="threading",
ping_timeout=20, ping_timeout=20,
ping_interval=10 ping_interval=10
) )
......
...@@ -41,3 +41,4 @@ tornado==4.5.2 ...@@ -41,3 +41,4 @@ tornado==4.5.2
urllib3==1.22 urllib3==1.22
wcwidth==0.1.7 wcwidth==0.1.7
Werkzeug==0.12.2 Werkzeug==0.12.2
eventlet==0.22
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment