Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore the original warnings.showwarning #1620

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions channels/management/commands/runserver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import logging
import sys
import warnings

from daphne.endpoints import build_endpoint_description_strings
from daphne.server import Server
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