From 59897a3cb9bb7d6dba7944bf6aa2271ef409e936 Mon Sep 17 00:00:00 2001 From: John Xina Date: Wed, 4 Oct 2023 10:11:46 +0800 Subject: [PATCH] fix proxify, workaround for memory leak --- README.md | 12 +++++++++--- proxify.py | 6 +++++- requirements.txt | 5 ++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b6f69c3..94736ec 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,21 @@ $ . venv/bin/activate ## 运行方法 +调试运行(已知在生产环境下有内存溢出): + ``` (venv) $ python main.py ``` -默认配置下,你应将反向代理指向 `127.0.0.1:8885`。 +生产环境运行: + +``` +(venv) $ gunicorn app:proxified --max-requests 50 --workers 2 --worker-class uvicorn.workers.UvicornWorker +``` + +默认参数下,你应将反向代理指向 `127.0.0.1:8000`。 ## 配置方法 -打开 `shared.py` 修改 `port` 后的数字来改变端口号。 - 其中的 `should_fetch_comments` 用于控制是否获取楼中楼。如果浏览性能不佳可以考虑 关闭楼中楼获取。 diff --git a/proxify.py b/proxify.py index e4f705f..8839a8a 100644 --- a/proxify.py +++ b/proxify.py @@ -47,7 +47,11 @@ class AsgiproxifyHandler(): headers.pop('Server', None) headers.pop('Date', None) - resp_headers = list(headers.items()) + bheaders = {} + for k, v in headers.items(): + bheaders[k.encode()] = v.encode() + + resp_headers = list(bheaders.items()) return resp_headers def make_request(self, session): diff --git a/requirements.txt b/requirements.txt index 008cbef..cd37921 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,8 @@ -aioflask==0.4.0 +aioflask flask==2.1.3 +Werkzeug==2.2.2 aiotieba aiohttp +uvicorn[standard] +gunicorn Flask-Caching