centos django Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING

os环境 centos

python2.7.5

django1.10.8

class AdminAutoRunTask(View):
    """
    自动跑外放任务
    """
    def post(self, request):
# 省略一些代码
for keyword, number in json.loads(task.keyword).items(): p = multiprocessing.Process(target=self.auto_run_task, args=(int(number), task.app_id.app_id, keyword)) p.start() log.info('auto_run_task: task_id=%s,keyword=%s, pid=%s' % (task.id, keyword, p.pid)) return JsonResponse({'code': 1, 'msg': 'success'})

views.py中post处理函数在return之前启动了一个或多个进程,然后虽然这里虽然return了,但是其实前端页面ajax并没有接收到数据。开发环境是好的os ubuntu

表现为ajax超时后抛出异常:net::ERR_INCOMPLETE_CHUNKED_ENCODING

解决方法把进程修改为线程

class AdminAutoRunTask(View):
    """
    自动跑外放任务
    """
    def post(self, request):
        # 省略一些代码

        for keyword, number in json.loads(task.keyword).items():
            p = threading.Thread(target=self.auto_run_task,
                                 args=(int(number), task.app_id.app_id, keyword))
            p.start()
            log.info('auto_run_task: task_id=%s,keyword=%s' % (task.id, keyword))

        return JsonResponse({'code': 1, 'msg': 'success'})

 

转载于:https://www.cnblogs.com/aaron-agu/p/10337485.html

你可能感兴趣的:(centos django Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING)