From 13fbe8a0740c3dc3239adef5d144166fcb1b2eea Mon Sep 17 00:00:00 2001 From: Mohammad Javad Naderi Date: Sat, 23 Jan 2021 17:38:34 +0330 Subject: [PATCH 1/2] Restore the original warnings.showwarning Fixes https://github.com/django/daphne/issues/352 --- channels/management/commands/runserver.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/channels/management/commands/runserver.py b/channels/management/commands/runserver.py index 3f5a48d71..abbb46e3d 100644 --- a/channels/management/commands/runserver.py +++ b/channels/management/commands/runserver.py @@ -1,4 +1,5 @@ import datetime +import warnings import logging import sys @@ -20,6 +21,7 @@ class Command(RunserverCommand): protocol = "http" server_cls = Server + old_showwarning = None def add_arguments(self, parser): super().add_arguments(parser) @@ -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, @@ -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: @@ -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, From c64644d359cecc697758f95a464f7ccea2d3658b Mon Sep 17 00:00:00 2001 From: Mohammad Javad Naderi Date: Mon, 25 Jan 2021 13:46:43 +0330 Subject: [PATCH 2/2] Make isort happy --- channels/management/commands/runserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels/management/commands/runserver.py b/channels/management/commands/runserver.py index abbb46e3d..46f17bdd1 100644 --- a/channels/management/commands/runserver.py +++ b/channels/management/commands/runserver.py @@ -1,7 +1,7 @@ import datetime -import warnings import logging import sys +import warnings from daphne.endpoints import build_endpoint_description_strings from daphne.server import Server