Open crocodilered opened 6 years ago
Complete code of server.py, that starts CP:
import os
import cherrypy
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
from webapp.libs.plugins.saplugin import SaPlugin
from webapp.libs.plugins.makoplugin import MakoTemplatePlugin
from webapp.libs.plugins.video_generator_plugin import VideoGeneratorPlugin
from webapp.libs.tools.makotool import MakoTool
from webapp.libs.tools.authtool import AuthTool
from webapp.libs.tools.satool import SaTool
from webapp.libs.ws_handler import WsHandler
def error_page(status, message, traceback, version):
""" HTTP errors handler """
if cherrypy.response.status == 401:
s = open('webapp/templates/errors/401.html', 'r', encoding='UTF-8').read()
return_url = '%s?%s' % (cherrypy.request.path_info, cherrypy.request.query_string)
return s % return_url.replace('?', '%3F').replace('/', '%2F')
elif cherrypy.response.status == 404:
return open('webapp/templates/errors/404.html', 'rb')
#########################################################
# Tools
#
cherrypy.tools.sa = SaTool()
cherrypy.tools.render = MakoTool()
cherrypy.tools.auth = AuthTool()
cherrypy.tools.websocket = WebSocketTool()
#########################################################
# Controllers
#
from webapp.controllers.app import App
from webapp.controllers.calculation import Calculation
from webapp.controllers.api import Api
from webapp.controllers.ws import WsController
app = App()
app.calculation = Calculation()
app.api = Api()
app.ws = WsController()
#########################################################
# Config
#
curr_dir = os.path.abspath(os.path.dirname(__file__))
conf_file = os.path.join(curr_dir, 'conf', 'server.conf')
application = cherrypy.tree.mount(app, '/', conf_file)
cherrypy.config.update(conf_file)
cherrypy.config.update({
'/ws': {
'tools.websocket.on': True,
'tools.websocket.handler_cls': WsHandler
}
})
cherrypy.config.update({'error_page.401': error_page})
cherrypy.config.update({'error_page.404': error_page})
#########################################################
# Plugins
#
MakoTemplatePlugin(cherrypy.engine,
os.path.join(curr_dir, 'templates'),
os.path.join(curr_dir, 'templates', '.cache')).subscribe()
ce_config = application.config['CalculationsEngine']
VideoGeneratorPlugin(cherrypy.engine,
ce_config['ce.ticks_to_generate_movie'],
ce_config['ce.movie_frame_rate']).subscribe()
db_config = application.config['Database']
mysql_connection_string = 'mysql://%s:%s@%s:%s/%s?charset=utf8' % (db_config['mysql.user'],
db_config['mysql.password'],
db_config['mysql.host'],
db_config['mysql.port'],
db_config['mysql.database'])
SaPlugin(cherrypy.engine, mysql_connection_string).subscribe()
WebSocketPlugin(cherrypy.engine).subscribe()
if __name__ == '__main__':
# For dev purpose
cherrypy.engine.start()
Hello.
I've arranged test project to learn ws4py and it worked perfect. But when I moved code to development env CherryPy start to go down right after start:
If I remove
WebSocketPlugin(cherrypy.engine).subscribe()
it starts okay but i need this plugin :-) Any suggestions how to force it work?