Debug mode not working in Django environment
Opened this issue · 0 comments
I try to use Tornado with sockjs-tornado in Django environment. In my project Tornado work as Websocket server together with Django in classic Django application.
From client I send session cookie to server and in Tornado get Django user:
from sockjs.tornado import SockJSConnection
from django.utils.importlib import import_module
from django.contrib.auth import get_user
from django.conf import settings
session_engine = import_module(settings.SESSION_ENGINE)
class ChatConnection(SockJSConnection):
def get_session(self, session_key):
return session_engine.SessionStore(session_key)
def get_user(self, session):
class Dummy(object):
pass
django_request = Dummy()
django_request.session = session
return get_user(django_request)
def auth(self, session_id):
self.django_session = self.get_session(session_id)
self.user = self.get_user(self.django_session)
def on_message(self, msg):
msg = json.loads(msg)
if msg['event'] == 'auth':
self.auth(msg['content'])
For run Tornado app in Django environment I use simple management command:
class Command(NoArgsCommand):
args = ''
help = 'Run tornado.'
def handle_noargs(self, **options):
app = Application(AppRouter.urls, **app_settings)
app.listen(8880)
tornado.ioloop.IOLoop.instance().start()
The problem is that in Django environment errors not raised, and Tornado just close connection instead of raise exception. For example, if I write assert False
in on_message
method, that it will not have any effect other than closed connection. In the app settings debug mode enabled:
app_settings = {
'debug': True,
}
Out of Django environment all work fine and I see in the shell excited exception.
Django 1.6.8
Tornado 4.0.2
sockjs-tornado 1.0.1