diff --git a/daphne/server.py b/daphne/server.py index 5341ab8..332b231 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -27,15 +27,18 @@ class Server(object): Run in a separate thread; reads messages from the backend. """ channels = self.factory.reply_channels() + delay = 0.3 # Quit if reactor is stopping if not reactor.running: logging.debug("Backend reader quitting due to reactor stop") return # Don't do anything if there's no channels to listen on if channels: + delay = 0.05 channel, message = self.channel_layer.receive_many(channels, block=False) if channel: + delay = 0 logging.debug("Server got message on %s", channel) # Deal with the message self.factory.dispatch_reply(channel, message) - reactor.callLater(0, self.backend_reader) + reactor.callLater(delay, self.backend_reader)