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
374402a7
Commit
374402a7
authored
May 24, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 优化eventlet
parent
20b5ab83
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
12 deletions
+21
-12
app.py
coco/app.py
+4
-0
httpd.py
coco/httpd.py
+13
-10
logger.py
coco/logger.py
+2
-0
requirements.txt
requirements/requirements.txt
+2
-2
No files found.
coco/app.py
View file @
374402a7
...
...
@@ -9,6 +9,8 @@ import threading
import
socket
import
json
import
signal
import
eventlet
from
eventlet.debug
import
hub_prevent_multiple_readers
from
jms.service
import
AppService
...
...
@@ -20,6 +22,8 @@ from .tasks import TaskHandler
from
.recorder
import
ReplayRecorder
,
CommandRecorder
from
.utils
import
get_logger
,
register_app
,
register_service
eventlet
.
monkey_patch
()
hub_prevent_multiple_readers
(
False
)
__version__
=
'1.3.0'
...
...
coco/httpd.py
View file @
374402a7
...
...
@@ -4,8 +4,6 @@
import
os
import
socket
import
uuid
import
eventlet
from
eventlet.debug
import
hub_prevent_multiple_readers
from
flask_socketio
import
SocketIO
,
Namespace
,
join_room
from
flask
import
Flask
,
request
,
current_app
,
redirect
...
...
@@ -15,12 +13,8 @@ from .utils import get_logger
from
.ctx
import
current_app
,
app_service
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
logger
=
get_logger
(
__file__
)
eventlet
.
monkey_patch
()
hub_prevent_multiple_readers
(
False
)
class
BaseNamespace
(
Namespace
):
current_user
=
None
...
...
@@ -173,11 +167,13 @@ class ProxyNamespace(BaseNamespace):
secret
=
message
.
get
(
'secret'
,
None
)
room
=
self
.
new_room
()
self
.
emit
(
'room'
,
{
'room'
:
room
[
"id"
],
'secret'
:
secret
})
self
.
socketio
.
sleep
(
0
)
if
not
token
or
not
secret
:
logger
.
debug
(
"Token or secret is None"
)
self
.
emit
(
'data'
,
{
'data'
:
"
\n
Operation not permitted!"
,
'room'
:
room
[
"id"
]})
self
.
emit
(
'disconnect'
)
self
.
socketio
.
sleep
(
0
)
return
None
info
=
app_service
.
get_token_asset
(
token
)
...
...
@@ -187,6 +183,7 @@ class ProxyNamespace(BaseNamespace):
self
.
emit
(
'data'
,
{
'data'
:
"
\n
Operation not permitted!"
,
'room'
:
room
[
"id"
]})
self
.
emit
(
'disconnect'
)
self
.
socketio
.
sleep
(
0
)
return
None
user_id
=
info
.
get
(
'user'
,
None
)
...
...
@@ -232,6 +229,9 @@ class ProxyNamespace(BaseNamespace):
del
self
.
connections
[
request
.
sid
][
room_id
]
del
room
def
on_ping
(
self
):
self
.
emit
(
'pong'
)
class
HttpServer
:
# prepare may be rewrite it
...
...
@@ -243,8 +243,10 @@ class HttpServer:
init_kwargs
=
dict
(
async_mode
=
"eventlet"
,
# async_mode="threading",
ping_timeout
=
20
,
ping_interval
=
10
# ping_timeout=20,
# ping_interval=10,
# engineio_logger=True,
# logger=True
)
def
__init__
(
self
):
...
...
@@ -269,7 +271,7 @@ class HttpServer:
def
run
(
self
):
host
=
self
.
flask_app
.
config
[
"BIND_HOST"
]
port
=
self
.
flask_app
.
config
[
"HTTPD_PORT"
]
print
(
'Starting websock server at {}:{}'
.
format
(
host
,
port
))
print
(
'Starting websock
et
server at {}:{}'
.
format
(
host
,
port
))
self
.
socket_io
.
init_app
(
self
.
flask_app
,
**
self
.
init_kwargs
...
...
@@ -277,4 +279,5 @@ class HttpServer:
self
.
socket_io
.
run
(
self
.
flask_app
,
port
=
port
,
host
=
host
,
debug
=
False
)
def
shutdown
(
self
):
self
.
socket_io
.
server
.
close
()
self
.
socket_io
.
stop
()
pass
coco/logger.py
View file @
374402a7
...
...
@@ -49,6 +49,8 @@ def create_logger(app):
'coco'
:
main_setting
,
'paramiko'
:
main_setting
,
'jms'
:
main_setting
,
'socket.io'
:
main_setting
,
'engineio'
:
main_setting
,
}
)
...
...
requirements/requirements.txt
View file @
374402a7
...
...
@@ -12,7 +12,7 @@ cryptography==2.1.4
docutils==0.14
dotmap==1.2.20
elasticsearch==6.1.1
Flask==
0.12
.2
Flask==
1.0
.2
Flask-SocketIO==2.9.2
idna==2.6
itsdangerous==0.24
...
...
@@ -40,5 +40,5 @@ six==1.11.0
tornado==4.5.2
urllib3==1.22
wcwidth==0.1.7
Werkzeug==0.1
2.2
Werkzeug==0.1
4.1
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