python - uwsgi/nginx 在子进程完成之前不响应
问题描述
我有带有 nginx 的服务器,将 http 流量传递给运行我的 django 应用程序的 uwsgi。我正在调用的 django 视图正在创建一个运行以下 test.sh bash 脚本的子进程:
#!/bin/sh
echo hello
sleep 10
echo morning
出于某种原因,在 bash 完成之前,我没有从视图中得到 200 响应,即打印“早上”,尽管子进程应该创建一个并行运行的线程。
在尝试调试此问题时,我注意到如果我在直接使用 djangopython manage.py runserver
或使用 uwsgi 运行时从服务器本地 cURL,http=127.0.0.1:8000
我会在预期的“早上”打印之前得到 200 响应。
任何想法为什么使用 socket=127.0.0.1:8000 和 nginx 它的行为不同?
我的 nginx 配置为将 http 流量传递给 django:
upstream django {
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
server {
listen 80;
location /api/ {
uwsgi_pass django;
include /path_to/uwsgi_params; # the uwsgi_params file you installed
}
}
我的uwsgi ini:
[uwsgi]
socket=127.0.0.1:8000
module=my_module.wsgi:application
chdir=/project_dir
master=true
vacuum=true
logger=file:/log_path
stats=/tmp/uwsgi_stats.socket
single interpreter=true
我的 view.py 是:
from subprocess import Popen
from rest_framework import views
from rest_framework.response import Response
class TestApi(views.APIView):
def post(self, request, *args, **kwargs):
Popen(["/opt/test.sh"])
return Response({})
解决方案
推荐阅读
- correlation - 协方差的重要性
- reporting-services - 汇总值并显示在图表中
- php - SVG数据未提交表单
- json - 未从集合中检索 ObjectIds (Scala + MongoDB)
- c++ - Gitlab - 访问同一实例上另一个项目的源
- javascript - 在树莓派 3 上从智能手机打开页面
- javascript - 无法扩展此 JavaScript 对象
- lstm - 是否可以制作具有 4 维数据形状的 LSTM 模型?
- oracle - 查询以检查 Oracle AQ 是启动还是停止
- c - 在设置二维数组的值时出现分段错误,即使循环计数器值在数组的 sizeof 内