Skip to content

Commit adb3719

Browse files
committed
removed the threadedhandler model in favor of pure gevent coroutines all the way. Works rather well but as a drawback with CherryPy as we need to monkey_patch all with gevent first. Need to change this behavior
1 parent 3f27a16 commit adb3719

4 files changed

Lines changed: 278 additions & 244 deletions

File tree

test/autobahn_test_servers.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- coding: utf-8 -*-
2+
from multiprocessing import Process
3+
4+
def run_cherrypy_server(host="127.0.0.1", port=9000):
5+
from gevent import monkey; monkey.patch_all()
6+
import cherrypy
7+
8+
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
9+
from ws4py.websocket import EchoWebSocket
10+
11+
cherrypy.config.update({'server.socket_host': host,
12+
'server.socket_port': port,
13+
'log.screen': False})
14+
WebSocketPlugin(cherrypy.engine).subscribe()
15+
cherrypy.tools.websocket = WebSocketTool()
16+
17+
class Root(object):
18+
@cherrypy.expose
19+
def index(self):
20+
pass
21+
22+
config = {
23+
'/': {
24+
'tools.websocket.on': True,
25+
'tools.websocket.handler_cls': EchoWebSocket
26+
}
27+
}
28+
cherrypy.quickstart(Root(), '/', config)
29+
30+
def run_gevent_server(host="127.0.0.1", port=9001):
31+
from gevent import monkey; monkey.patch_all()
32+
from ws4py.server.geventserver import WebSocketServer
33+
from ws4py.websocket import EchoWebSocket
34+
35+
server = WebSocketServer((host, port), websocket_class=EchoWebSocket)
36+
server.serve_forever()
37+
38+
if __name__ == '__main__':
39+
p0 = Process(target=run_cherrypy_server)
40+
p0.daemon = True
41+
p0.start()
42+
43+
p1 = Process(target=run_gevent_server)
44+
p1.daemon = True
45+
p1.start()
46+
47+
p0.join()
48+
p1.join()

ws4py/server/handler/__init__.py

Whitespace-only changes.

ws4py/server/handler/tornadohandler.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)