Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
coco
Commits
20c7b2db
Commit
20c7b2db
authored
May 23, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 使用eventlet, websocket支持
parent
f3df8adb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
6 deletions
+12
-6
app.py
coco/app.py
+5
-3
httpd.py
coco/httpd.py
+6
-3
requirements.txt
requirements/requirements.txt
+1
-0
No files found.
coco/app.py
View file @
20c7b2db
...
...
@@ -218,9 +218,11 @@ class Coco:
self
.
run_httpd
()
signal
.
signal
(
signal
.
SIGTERM
,
lambda
x
,
y
:
self
.
shutdown
())
while
self
.
stop_evt
.
wait
(
5
):
print
(
"Coco receive term signal, exit"
)
break
while
True
:
if
self
.
stop_evt
.
is_set
():
print
(
"Coco receive term signal, exit"
)
break
time
.
sleep
(
3
)
except
KeyboardInterrupt
:
self
.
stop_evt
.
set
()
self
.
shutdown
()
...
...
coco/httpd.py
View file @
20c7b2db
...
...
@@ -4,6 +4,7 @@
import
os
import
socket
import
uuid
import
eventlet
from
flask_socketio
import
SocketIO
,
Namespace
,
join_room
from
flask
import
Flask
,
request
,
current_app
,
redirect
...
...
@@ -16,6 +17,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
logger
=
get_logger
(
__file__
)
eventlet
.
monkey_patch
()
class
BaseNamespace
(
Namespace
):
current_user
=
None
...
...
@@ -23,7 +26,7 @@ class BaseNamespace(Namespace):
def
on_connect
(
self
):
self
.
current_user
=
self
.
get_current_user
()
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
))
def
get_current_user
(
self
):
...
...
@@ -236,8 +239,8 @@ class HttpServer:
'LOGIN_URL'
:
'/login'
}
init_kwargs
=
dict
(
# async_mode="geven
t",
async_mode
=
"threading"
,
async_mode
=
"eventle
t"
,
#
async_mode="threading",
ping_timeout
=
20
,
ping_interval
=
10
)
...
...
requirements/requirements.txt
View file @
20c7b2db
...
...
@@ -41,3 +41,4 @@ tornado==4.5.2
urllib3==1.22
wcwidth==0.1.7
Werkzeug==0.12.2
eventlet==0.22
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment