From 07801e9ae8c90f9832f5436a22b0485c2312b78b Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 23 Feb 2016 21:23:55 +0000 Subject: [PATCH] Make daphne serving thread idle better --- daphne/server.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)