django - 在 docker 中使用 gunicorn 运行 Django 并重新加载会产生 TypeError
问题描述
Django 版本:2.2.23
一切正常。但是,当我尝试将--reload
标志与 gunicorn 一起使用时,会导致以下错误:
[2021-06-08 09:48:07 +0000] [79] [INFO] Starting gunicorn 19.7.1
[2021-06-08 09:48:07 +0000] [79] [INFO] Listening at: http://0.0.0.0:8000 (79)
[2021-06-08 09:48:07 +0000] [79] [INFO] Using worker: sync
/usr/lib/python3.8/os.py:1023: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
return io.open(fd, *args, **kwargs)
[2021-06-08 09:48:07 +0000] [81] [INFO] Booting worker with pid: 81
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.8/dist-packages/gunicorn/reloader.py", line 42, in run
for filename in self.get_files():
File "/usr/local/lib/python3.8/dist-packages/gunicorn/reloader.py", line 28, in get_files
fnames = [
File "/usr/local/lib/python3.8/dist-packages/gunicorn/reloader.py", line 29, in <listcomp>
re.sub('py[co]$', 'py', module.__file__)
File "/usr/lib/python3.8/re.py", line 210, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
这是我的码头文件:
#20.04-LTS
FROM ubuntu:focal
RUN apt update
# install python
RUN apt install -y git python python3 python3-dev python3-pip python3-virtualenv && pip3 install --upgrade pip
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN mkdir /web
WORKDIR /web
ADD requirements.txt /web/
RUN pip3 install -r requirements.txt
COPY . /web
我的码头工人撰写:
version: '2'
services:
web:
build: .
depends_on:
- db
- redis
volumes:
- .:/web
ports:
- "8000:8000"
command: bash -c "./entrypoint.sh"
我的 entrypoint.sh:
#!/bin/bash
# Collect static files
echo "Collecting static files"
python3 manage.py collectstatic --noinput
# Apply database migrations
echo "Applying database migrations"
python3 manage.py migrate
# Start server
echo "Starting server"
gunicorn app.wsgi -b 0.0.0.0:8000 --reload
解决方案
推荐阅读
- azure - 如何在 cosmos db 中添加大小超过 2 mb 的数据作为单个条目?
- python - 我可以将 opencv VideoWriter 的输出保存到 AWS S3 存储吗?
- javascript - Material UI svg Icon:找不到模块:错误:无法解析'@material-ui/icons/...'
- firebase - 无法从 Firestore 集合的子集合中查询文档
- genetic-algorithm - 遗传算法中的锦标赛选择和精英主义有什么区别?
- bash - 如何在 Bash/sh 中将用户帐户名称和目录分配给数组?
- salt-stack - 盐栈在状态失败时执行命令/调用不同的状态
- javascript - 页面缩小时如何保留导航栏上的社交链接,以及打开汉堡菜单时如何将社交图标放在同一行
- python - SQL查询的python等效哈希
- java - 如何在 for 循环的第二次迭代中检查条件?