From 61b8940e9978cbedf9408fa4340858ac1c96fabc Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 28 Feb 2016 21:52:35 -0800 Subject: [PATCH] Warn when trying to use runworker with in memory layer --- channels/asgi.py | 4 ++++ channels/management/commands/runworker.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/channels/asgi.py b/channels/asgi.py index 29eacc3..9911578 100644 --- a/channels/asgi.py +++ b/channels/asgi.py @@ -75,6 +75,10 @@ class ChannelLayerWrapper(object): def __str__(self): return "%s (%s)" % (self.alias, name_that_thing(self.channel_layer)) + def local_only(self): + # TODO: Can probably come up with a nicer check? + return "inmemory" in self.channel_layer.__class__.__module__ + def get_channel_layer(alias="default"): """ diff --git a/channels/management/commands/runworker.py b/channels/management/commands/runworker.py index 35fd38e..e5fa5ff 100644 --- a/channels/management/commands/runworker.py +++ b/channels/management/commands/runworker.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from django.core.management import BaseCommand +from django.core.management import BaseCommand, CommandError from channels import channel_layers, DEFAULT_CHANNEL_LAYER from channels.log import setup_logger from channels.worker import Worker @@ -13,6 +13,12 @@ class Command(BaseCommand): self.verbosity = options.get("verbosity", 1) self.logger = setup_logger('django.channels', self.verbosity) self.channel_layer = channel_layers[DEFAULT_CHANNEL_LAYER] + # Check that handler isn't inmemory + if self.channel_layer.local_only(): + raise CommandError( + "You cannot span multiple processes with the in-memory layer. " + + "Change your settings to use a cross-process channel layer." + ) # Check a handler is registered for http reqs self.channel_layer.registry.check_default() # Launch a worker