Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug mode not working in Django environment #74

Open
tangochin opened this issue Jan 13, 2015 · 0 comments
Open

Debug mode not working in Django environment #74

tangochin opened this issue Jan 13, 2015 · 0 comments

Comments

@tangochin
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant