def main(settings_file, logfile=None): os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_file) if logfile: import datetime class logger(object): def __init__(self, logfile): self.logfile = logfile def write(self, data): self.log(data) def writeline(self, data): self.log(data) def log(self, msg): line = '%s - %s\n' % ( datetime.datetime.now().strftime('%Y%m%d %H:%M:%S'), msg) fp = open(self.logfile, 'a') try: fp.write(line) finally: fp.close() sys.stdout = sys.stderr = logger(logfile) redis.connection.socket = gevent.socket return uWSGIWebsocketServer()
def application(environ, start_response): from django.conf import settings if environ.get('PATH_INFO').startswith(settings.WEBSOCKET_URL): from ws4redis.uwsgi_runserver import uWSGIWebsocketServer _websockets = uWSGIWebsocketServer() return _websockets(environ, start_response) return _webserver(environ, start_response)
# entry point for the Django loop import os if not os.environ.has_key('DJANGO_SETTINGS_MODULE'): os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chatserver.settings') from django.conf import settings from django.core.wsgi import get_wsgi_application from ws4redis.uwsgi_runserver import uWSGIWebsocketServer from whitenoise.django import DjangoWhiteNoise application = get_wsgi_application() _django_app = DjangoWhiteNoise(application) _websocket_app = uWSGIWebsocketServer() def application(environ, start_response): if environ.get('PATH_INFO').startswith(settings.WEBSOCKET_URL): return _websocket_app(environ, start_response) return _django_app(environ, start_response)
# entry point for the websocket loop import gevent.monkey import redis.connection redis.connection.socket = gevent.socket from ws4redis.uwsgi_runserver import uWSGIWebsocketServer application = uWSGIWebsocketServer()