如何解决django gunicorn 在发送文件时卡住
我使用了 django、docker、nginx 和 gunicorn
如果我尝试使用开发模式(在我的本地运行),它工作正常 当我的服务器发送 PDF(仍在下载)时,我仍然可以调用另一个 API
但是在我的 docker 上,它就像一个工人,当服务器发送一个文件,而我们调用另一个 API 时,服务器卡在等待先发送 PDF 完成。我已经设置了工作线程 9 和线程 2 但仍然有同样的问题。
这是我的 docker-compose
version: '3'
services:
web:
build:
context: ./app
dockerfile: Dockerfile.prod
command: gunicorn --workers=9 --threads=2 server.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_volume:/home/app/web/staticfiles
expose:
- 8000
env_file:
- ./app/config/.env
nginx:
build: ./nginx
volumes:
- static_volume:/home/app/web/staticfiles
ports:
- 80:80
depends_on:
- web
volumes:
static_volume:
我的看法
try:
test_file = open(pdf_path,'rb')
response = HttpResponse(content=test_file)
response['Content-Type'] = 'application/pdf'
response['Content-Disposition'] = 'attachment; filename="flp_{}.pdf"'.format(email_phone)
print("send pdf")
return response
except FileNotFoundError:
print("send pdf exception file not found")
raise Http404()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。