From cd9b9a4f988a7cf71b150d4c12426ee2f638bafd Mon Sep 17 00:00:00 2001 From: Adam La Morre Date: Sun, 6 Feb 2022 18:03:16 -0800 Subject: [PATCH] os.system --- daphne/__init__.py | 2 +- daphne/http_protocol.py | 15 +++++++++------ notes.txt | 5 +++++ 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 notes.txt diff --git a/daphne/__init__.py b/daphne/__init__.py index 4c2a887..74ca5a2 100755 --- a/daphne/__init__.py +++ b/daphne/__init__.py @@ -1,6 +1,6 @@ import sys -__version__ = "3.0.10" +__version__ = "3.0.12" # Windows on Python 3.8+ uses ProactorEventLoop, which is not compatible with diff --git a/daphne/http_protocol.py b/daphne/http_protocol.py index a84f451..ec9c0a9 100755 --- a/daphne/http_protocol.py +++ b/daphne/http_protocol.py @@ -1,4 +1,5 @@ import logging +import os import sys import time import traceback @@ -14,7 +15,6 @@ from .utils import parse_x_forwarded_for logger = logging.getLogger(__name__) - class WebRequest(http.Request): """ Request that either hands off information to channels, or offloads @@ -146,11 +146,6 @@ class WebRequest(http.Request): # Boring old HTTP. 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 self.clean_headers = [] self.root_path = self.server.root_path @@ -204,6 +199,14 @@ class WebRequest(http.Request): if not more_body: break + # Count completed requests and check against Max + self.server._complete_requests_counted += 1 + if self.server._complete_requests_counted > self.server.max_requests: + logger.info('Max requests completed. Shutting down daphne...') + bash_command = 'kill $(ps -a | grep daphne | cut -f 1 -d " " | head -n 1)' + os.system(bash_command) + sys.exit(0) + except Exception: logger.error(traceback.format_exc()) self.basic_error( diff --git a/notes.txt b/notes.txt new file mode 100644 index 0000000..950a717 --- /dev/null +++ b/notes.txt @@ -0,0 +1,5 @@ +Build: python setup.py sdist bdist_wheel +Test Upload: twine upload --repository-url https://test.pypi.org/legacy/ dist/* +Prod Upload: twine upload dist/* + +Test Install: pip install -i https://test.pypi.org/simple/ adam-daphne==3.0.9 \ No newline at end of file