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'})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM