mirror of
https://github.com/django/daphne.git
synced 2025-07-15 02:12:17 +03:00
working
This commit is contained in:
parent
a75b67b395
commit
aae49a0bae
|
@ -154,6 +154,7 @@ class CommandLineInterface:
|
||||||
help="The maximum number of requests a worker will process before restarting.",
|
help="The maximum number of requests a worker will process before restarting.",
|
||||||
default=float('inf'),
|
default=float('inf'),
|
||||||
action="store",
|
action="store",
|
||||||
|
type=int,
|
||||||
)
|
)
|
||||||
self.parser.add_argument(
|
self.parser.add_argument(
|
||||||
"application",
|
"application",
|
||||||
|
@ -266,6 +267,7 @@ class CommandLineInterface:
|
||||||
endpoints = sorted(args.socket_strings + endpoints)
|
endpoints = sorted(args.socket_strings + endpoints)
|
||||||
# Start the server
|
# Start the server
|
||||||
logger.info("Starting server at {}".format(", ".join(endpoints)))
|
logger.info("Starting server at {}".format(", ".join(endpoints)))
|
||||||
|
logger.info(args.max_requests)
|
||||||
self.server = self.server_class(
|
self.server = self.server_class(
|
||||||
application=application,
|
application=application,
|
||||||
endpoints=endpoints,
|
endpoints=endpoints,
|
||||||
|
@ -288,5 +290,6 @@ class CommandLineInterface:
|
||||||
if args.proxy_headers
|
if args.proxy_headers
|
||||||
else None,
|
else None,
|
||||||
server_name=args.server_name,
|
server_name=args.server_name,
|
||||||
|
max_requests=args.max_requests,
|
||||||
)
|
)
|
||||||
self.server.run()
|
self.server.run()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
@ -56,7 +57,6 @@ class WebRequest(http.Request):
|
||||||
self.server = self.channel.factory.server
|
self.server = self.channel.factory.server
|
||||||
self.application_queue = None
|
self.application_queue = None
|
||||||
self._response_started = False
|
self._response_started = False
|
||||||
self._complete_requests_counted = 0
|
|
||||||
self.server.protocol_connected(self)
|
self.server.protocol_connected(self)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
|
@ -146,6 +146,11 @@ class WebRequest(http.Request):
|
||||||
|
|
||||||
# Boring old HTTP.
|
# Boring old HTTP.
|
||||||
else:
|
else:
|
||||||
|
# Count completed Request and check against Max Requests
|
||||||
|
self.server._complete_requests_counted += 1
|
||||||
|
if self.server._complete_requests_counted > self.server.max_requests:
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# Sanitize and decode headers, potentially extracting root path
|
# Sanitize and decode headers, potentially extracting root path
|
||||||
self.clean_headers = []
|
self.clean_headers = []
|
||||||
self.root_path = self.server.root_path
|
self.root_path = self.server.root_path
|
||||||
|
@ -198,10 +203,6 @@ class WebRequest(http.Request):
|
||||||
self.application_queue.put_nowait(payload)
|
self.application_queue.put_nowait(payload)
|
||||||
if not more_body:
|
if not more_body:
|
||||||
break
|
break
|
||||||
# Count completed Request and check against Max Requests
|
|
||||||
self._complete_requests_counted += 1
|
|
||||||
if self._complete_requests_counted > self.server.max_requests:
|
|
||||||
self.server.close()
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
|
|
|
@ -84,6 +84,7 @@ class Server:
|
||||||
self.ready_callable = ready_callable
|
self.ready_callable = ready_callable
|
||||||
self.server_name = server_name
|
self.server_name = server_name
|
||||||
self.max_requests = max_requests
|
self.max_requests = max_requests
|
||||||
|
self._complete_requests_counted = 0
|
||||||
# Check our construction is actually sensible
|
# Check our construction is actually sensible
|
||||||
if not self.endpoints:
|
if not self.endpoints:
|
||||||
logger.error("No endpoints. This server will not listen on anything.")
|
logger.error("No endpoints. This server will not listen on anything.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user