mirror of
https://github.com/django/daphne.git
synced 2024-11-22 07:56:34 +03:00
Make daphne serving thread idle better
This commit is contained in:
parent
b5400d0be5
commit
07801e9ae8
|
@ -27,15 +27,18 @@ class Server(object):
|
||||||
Run in a separate thread; reads messages from the backend.
|
Run in a separate thread; reads messages from the backend.
|
||||||
"""
|
"""
|
||||||
channels = self.factory.reply_channels()
|
channels = self.factory.reply_channels()
|
||||||
|
delay = 0.3
|
||||||
# Quit if reactor is stopping
|
# Quit if reactor is stopping
|
||||||
if not reactor.running:
|
if not reactor.running:
|
||||||
logging.debug("Backend reader quitting due to reactor stop")
|
logging.debug("Backend reader quitting due to reactor stop")
|
||||||
return
|
return
|
||||||
# Don't do anything if there's no channels to listen on
|
# Don't do anything if there's no channels to listen on
|
||||||
if channels:
|
if channels:
|
||||||
|
delay = 0.05
|
||||||
channel, message = self.channel_layer.receive_many(channels, block=False)
|
channel, message = self.channel_layer.receive_many(channels, block=False)
|
||||||
if channel:
|
if channel:
|
||||||
|
delay = 0
|
||||||
logging.debug("Server got message on %s", channel)
|
logging.debug("Server got message on %s", channel)
|
||||||
# Deal with the message
|
# Deal with the message
|
||||||
self.factory.dispatch_reply(channel, message)
|
self.factory.dispatch_reply(channel, message)
|
||||||
reactor.callLater(0, self.backend_reader)
|
reactor.callLater(delay, self.backend_reader)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user