Make the location of channels in INSTALLED_APPS not matter

This commit is contained in:
Andrew Godwin 2015-07-13 15:51:10 -05:00
parent 7cfb3139dd
commit 6e91ea0040
4 changed files with 21 additions and 3 deletions

View File

@ -12,9 +12,7 @@ channel_backends = BackendManager(
})
)
# Ensure monkeypatching
from .hacks import monkeypatch_django
monkeypatch_django()
default_app_config = 'channels.apps.ChannelsConfig'
# Promote channel to top-level (down here to avoid circular import errs)
from .channel import Channel, Group

11
channels/apps.py Normal file
View File

@ -0,0 +1,11 @@
from django.apps import AppConfig
class ChannelsConfig(AppConfig):
name = "channels"
verbose_name = "Channels"
def ready(self):
# Do django monkeypatches
from .hacks import monkeypatch_django
monkeypatch_django()

View File

@ -19,6 +19,11 @@ def monkeypatch_django():
# Allow ResponseLater to propagate above handler
BaseHandler.old_handle_uncaught_exception = BaseHandler.handle_uncaught_exception
BaseHandler.handle_uncaught_exception = new_handle_uncaught_exception
# Ensure that the staticfiles version of runserver bows down to us
# This one is particularly horrible
from django.contrib.staticfiles.management.commands.runserver import Command as StaticRunserverCommand
from .management.commands.runserver import Command as RunserverCommand
StaticRunserverCommand.__bases__ = (RunserverCommand, )
def new_handle_uncaught_exception(self, request, resolver, exc_info):

View File

@ -30,6 +30,10 @@ class Command(RunserverCommand):
worker = WorkerThread(self.channel_backend)
worker.daemon = True
worker.start()
# Note that this is the right one on the console
self.stdout.write("Worker thread running, channels enabled")
if self.channel_backend.local_only:
self.stdout.write("Local channel backend detected, no remote channels support")
# Run the rest
return super(Command, self).run(*args, **options)