centos django Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING

os環境 centos前端

python2.7.5python

django1.10.8ajax

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 ubuntudjango

表現爲ajax超時後拋出異常:net::ERR_INCOMPLETE_CHUNKED_ENCODINGjson

解決方法把進程修改成線程ubuntu

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'})
相關文章
相關標籤/搜索