-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebSocket support for threading mode
- Loading branch information
1 parent
7c6b05c
commit b84537a
Showing
5 changed files
with
74 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,48 @@ | ||
from __future__ import absolute_import | ||
import queue | ||
import threading | ||
import time | ||
|
||
try: | ||
import queue | ||
from simple_websocket import Server, ConnectionClosed | ||
_websocket_available = True | ||
except ImportError: # pragma: no cover | ||
import Queue as queue | ||
_websocket_available = False | ||
|
||
|
||
class WebSocketWSGI(object): # pragma: no cover | ||
""" | ||
This wrapper class provides a threading WebSocket interface that is | ||
compatible with eventlet's implementation. | ||
""" | ||
def __init__(self, app): | ||
self.app = app | ||
|
||
def __call__(self, environ, start_response): | ||
self.ws = Server(environ) | ||
return self.app(self) | ||
|
||
def close(self): | ||
return 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: | ||
raise IOError() | ||
|
||
|
||
_async = { | ||
'thread': threading.Thread, | ||
'queue': queue.Queue, | ||
'queue_empty': queue.Empty, | ||
'event': threading.Event, | ||
'websocket': None, | ||
'websocket': WebSocketWSGI if _websocket_available else None, | ||
'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
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