-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace gevent-websocket with simple-websocket when using gevent
- Loading branch information
1 parent
fae2635
commit 614f564
Showing
6 changed files
with
90 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import simple_websocket | ||
|
||
|
||
class SimpleWebSocketWSGI: # pragma: no cover | ||
""" | ||
This wrapper class provides a threading WebSocket interface that is | ||
compatible with eventlet's implementation. | ||
""" | ||
def __init__(self, handler, server, **kwargs): | ||
self.app = handler | ||
self.server_args = kwargs | ||
|
||
def __call__(self, environ, start_response): | ||
self.ws = simple_websocket.Server(environ, **self.server_args) | ||
ret = self.app(self) | ||
if self.ws.mode == 'gunicorn': | ||
raise StopIteration() | ||
return ret | ||
|
||
def close(self): | ||
if self.ws.connected: | ||
self.ws.close() | ||
|
||
def send(self, message): | ||
try: | ||
return self.ws.send(message) | ||
except simple_websocket.ConnectionClosed: | ||
raise IOError() | ||
|
||
def wait(self): | ||
try: | ||
return self.ws.receive() | ||
except simple_websocket.ConnectionClosed: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,19 @@ | ||
from __future__ import absolute_import | ||
import queue | ||
import threading | ||
import time | ||
|
||
try: | ||
from simple_websocket import Server, ConnectionClosed | ||
_websocket_available = True | ||
except ImportError: # pragma: no cover | ||
_websocket_available = False | ||
from engineio.async_drivers._websocket_wsgi import SimpleWebSocketWSGI | ||
|
||
|
||
class DaemonThread(threading.Thread): # pragma: no cover | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs, daemon=True) | ||
|
||
|
||
class WebSocketWSGI(object): # pragma: no cover | ||
""" | ||
This wrapper class provides a threading WebSocket interface that is | ||
compatible with eventlet's implementation. | ||
""" | ||
def __init__(self, handler, server): | ||
self.app = handler | ||
|
||
def __call__(self, environ, start_response): | ||
self.ws = Server(environ) | ||
ret = self.app(self) | ||
if self.ws.mode == 'gunicorn': | ||
raise StopIteration() | ||
return ret | ||
|
||
def close(self): | ||
if self.ws.connected: | ||
self.ws.close() | ||
|
||
def send(self, message): | ||
try: | ||
return self.ws.send(message) | ||
except ConnectionClosed: | ||
raise IOError() | ||
|
||
def wait(self): | ||
try: | ||
return self.ws.receive() | ||
except ConnectionClosed: | ||
return None | ||
|
||
|
||
_async = { | ||
'thread': DaemonThread, | ||
'queue': queue.Queue, | ||
'queue_empty': queue.Empty, | ||
'event': threading.Event, | ||
'websocket': WebSocketWSGI if _websocket_available else None, | ||
'websocket': SimpleWebSocketWSGI, | ||
'sleep': time.sleep, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters