Skip to content

Commit

Permalink
Improve websocket connection
Browse files Browse the repository at this point in the history
This commit will improve the websocket to use gevent + gevent-websocket to avoid
the error KeyError: 'Session is disconnected'
Fix kytos#416
  • Loading branch information
macartur committed May 19, 2017
1 parent 781c926 commit a59ffcc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
9 changes: 2 additions & 7 deletions etc/kytos/logging.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ keys: console,syslog
keys: console,syslog

[loggers]
keys: root,api_server,socket
keys: root,api_server

[formatter_syslog]
format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s
Expand All @@ -29,10 +29,5 @@ handlers: syslog,console

[logger_api_server]
level: INFO
qualname: werkzeug
handlers:

[logger_socket]
level: ERROR
qualname: engineio
qualname: geventwebsocket.handler
handlers:
2 changes: 1 addition & 1 deletion kytos/core/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, app_name, debug=False):
self.set_debug(debug)

self.app = Flask(app_name, root_path=self.flask_dir)
self.server = SocketIO(self.app, async_mode='threading')
self.server = SocketIO(self.app)

def set_debug(self, debug):
"""Method used to set debug mode.
Expand Down
2 changes: 1 addition & 1 deletion kytos/core/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def update_buffer(self):
self.stream.truncate(0)

if len(self.buff) >= self.buffer_max_size:
new_size = self.buffer_max_size/2
new_size = int(self.buffer_max_size/2)
self.buff = self.buff[new_size:]

def handle_messages(self, json):
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ python-daemon>=2.1.2
# Maybe we need to remove this on the future
setuptools>=34.0.0
jinja2
gevent-websocket
gevent

0 comments on commit a59ffcc

Please sign in to comment.