Skip to content

Commit

Permalink
Restore the original warnings.showwarning
Browse files Browse the repository at this point in the history
  • Loading branch information
mjnaderi authored Jan 23, 2021
1 parent 8eee419 commit 13fbe8a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions channels/management/commands/runserver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import warnings
import logging
import sys

Expand All @@ -20,6 +21,7 @@
class Command(RunserverCommand):
protocol = "http"
server_cls = Server
old_showwarning = None

def add_arguments(self, parser):
super().add_arguments(parser)
Expand Down Expand Up @@ -103,6 +105,7 @@ def inner_run(self, *args, **options):
# build the endpoint description string from host/port options
endpoints = build_endpoint_description_strings(host=self.addr, port=self.port)
try:
self.old_showwarning = warnings.showwarning
self.server_cls(
application=self.get_application(options),
endpoints=endpoints,
Expand All @@ -111,6 +114,7 @@ def inner_run(self, *args, **options):
http_timeout=self.http_timeout,
root_path=getattr(settings, "FORCE_SCRIPT_NAME", "") or "",
websocket_handshake_timeout=self.websocket_handshake_timeout,
ready_callable=self.restore_showwarnings,
).run()
logger.debug("Daphne exited")
except KeyboardInterrupt:
Expand All @@ -119,6 +123,10 @@ def inner_run(self, *args, **options):
self.stdout.write(shutdown_message)
return

def restore_showwarnings(self):
if self.old_showwarning:
warnings.showwarning = self.old_showwarning

def get_application(self, options):
"""
Returns the static files serving application wrapping the default application,
Expand Down

0 comments on commit 13fbe8a

Please sign in to comment.