diff --git a/channels/__init__.py b/channels/__init__.py index e5d43b7..2ee5420 100644 --- a/channels/__init__.py +++ b/channels/__init__.py @@ -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 diff --git a/channels/apps.py b/channels/apps.py new file mode 100644 index 0000000..2d31d8d --- /dev/null +++ b/channels/apps.py @@ -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() diff --git a/channels/hacks.py b/channels/hacks.py index e3003cf..e782eb6 100644 --- a/channels/hacks.py +++ b/channels/hacks.py @@ -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): diff --git a/channels/management/commands/runserver.py b/channels/management/commands/runserver.py index 7a795bc..50dca7e 100644 --- a/channels/management/commands/runserver.py +++ b/channels/management/commands/runserver.py @@ -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)