Make runserver work with autoreload

This commit is contained in:
Andrew Godwin 2015-09-03 00:07:57 -07:00
parent 832809ca25
commit 16a0e73c6c

View File

@ -18,24 +18,26 @@ class Command(RunserverCommand):
return WSGIInterface(self.channel_backend) return WSGIInterface(self.channel_backend)
def run(self, *args, **options): def run(self, *args, **options):
# Force disable reloader for now # Run the rest
options['use_reloader'] = False return super(Command, self).run(*args, **options)
def inner_run(self, *args, **options):
# Check a handler is registered for http reqs # Check a handler is registered for http reqs
self.channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND] self.channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
auto_import_consumers() auto_import_consumers()
if not self.channel_backend.registry.consumer_for_channel("django.wsgi.request"): if not self.channel_backend.registry.consumer_for_channel("django.wsgi.request"):
# Register the default one # Register the default one
self.channel_backend.registry.add_consumer(UrlConsumer(), ["django.wsgi.request"]) self.channel_backend.registry.add_consumer(UrlConsumer(), ["django.wsgi.request"])
# Launch a worker thread
worker = WorkerThread(self.channel_backend)
worker.daemon = True
worker.start()
# Note that this is the right one on the console # Note that this is the right one on the console
self.stdout.write("Worker thread running, channels enabled") self.stdout.write("Worker thread running, channels enabled")
if self.channel_backend.local_only: if self.channel_backend.local_only:
self.stdout.write("Local channel backend detected, no remote channels support") self.stdout.write("Local channel backend detected, no remote channels support")
# Run the rest # Launch a worker thread
return super(Command, self).run(*args, **options) worker = WorkerThread(self.channel_backend)
worker.daemon = True
worker.start()
# Run rest of inner run
super(Command, self).inner_run(*args, **options)
class WorkerThread(threading.Thread): class WorkerThread(threading.Thread):