def judge(self): self.submission.judge_start_time = int(time.time() * 1000) with transaction.atomic(): judge_server = self.choose_judge_server() # 如果没有合适的判题服务器,就放入等待队列中等待判题 if not judge_server: JudgeWaitingQueue.objects.create(submission_id=self.submission.id, time_limit=self.time_limit, memory_limit=self.memory_limit, test_case_id=self.test_case_id) return judge_server.use_judge_instance() try: s = TimeoutServerProxy("http://" + judge_server.ip + ":" + str(judge_server.port), timeout=20) data = s.run(judge_server.token, self.submission.id, self.submission.language, self.submission.code, self.time_limit, self.memory_limit, self.test_case_id) # 编译错误 if data["code"] == 1: self.submission.result = result["compile_error"] self.submission.info = data["data"]["error"] # system error elif data["code"] == 2: self.submission.result = result["system_error"] self.submission.info = data["data"]["error"] elif data["code"] == 0: self.submission.result = data["data"]["result"] self.submission.info = json.dumps(data["data"]["info"]) self.submission.accepted_answer_time = data["data"]["accepted_answer_time"] except Exception as e: self.submission.result = result["system_error"] self.submission.info = str(e) finally: with transaction.atomic(): judge_server.release_judge_instance() self.submission.judge_end_time = int(time.time() * 1000) self.submission.save() if self.submission.contest_id: self.update_contest_problem_status() else: self.update_problem_status() with transaction.atomic(): waiting_submissions = JudgeWaitingQueue.objects.select_for_update().all() if waiting_submissions.exists(): # 防止循环依赖 from submission.tasks import _judge waiting_submission = waiting_submissions.first() submission = Submission.objects.get(id=waiting_submission.submission_id) waiting_submission.delete() _judge.delay(submission, time_limit=waiting_submission.time_limit, memory_limit=waiting_submission.memory_limit, test_case_id=waiting_submission.test_case_id, is_waiting_task=True)
def judge(self): self.submission.judge_start_time = int(time.time() * 1000) with transaction.atomic(): judge_server = self.choose_judge_server() # 如果没有合适的判题服务器,就放入等待队列中等待判题 if not judge_server: JudgeWaitingQueue.objects.create( submission_id=self.submission.id, time_limit=self.time_limit, memory_limit=self.memory_limit, test_case_id=self.test_case_id) return judge_server.use_judge_instance() try: s = TimeoutServerProxy("http://" + judge_server.ip + ":" + str(judge_server.port), timeout=20) data = s.run(judge_server.token, self.submission.id, self.submission.language, self.submission.code, self.time_limit, self.memory_limit, self.test_case_id) # 编译错误 if data["code"] == 1: self.submission.result = result["compile_error"] self.submission.info = data["data"]["error"] # system error elif data["code"] == 2: self.submission.result = result["system_error"] self.submission.info = data["data"]["error"] elif data["code"] == 0: self.submission.result = data["data"]["result"] self.submission.info = json.dumps(data["data"]["info"]) self.submission.accepted_answer_time = data["data"][ "accepted_answer_time"] except Exception as e: self.submission.result = result["system_error"] self.submission.info = str(e) finally: with transaction.atomic(): judge_server.release_judge_instance() self.submission.judge_end_time = int(time.time() * 1000) self.submission.save() if self.submission.contest_id: self.update_contest_problem_status() else: self.update_problem_status() with transaction.atomic(): waiting_submissions = JudgeWaitingQueue.objects.select_for_update( ).all() if waiting_submissions.exists(): # 防止循环依赖 from submission.tasks import _judge waiting_submission = waiting_submissions.first() submission = Submission.objects.get( id=waiting_submission.submission_id) waiting_submission.delete() _judge.delay(submission, time_limit=waiting_submission.time_limit, memory_limit=waiting_submission.memory_limit, test_case_id=waiting_submission.test_case_id, is_waiting_task=True)
def judge(self): self.submission.judge_start_time = int(time.time() * 1000) judge_server = self.choose_judge_server() # 如果没有合适的判题服务器,就放入等待队列中等待判题 if not judge_server: JudgeWaitingQueue.objects.create(submission_id=self.submission.id, time_limit=self.time_limit, memory_limit=self.memory_limit, test_case_id=self.test_case_id, spj=self.spj, spj_language=self.spj_language, spj_code=self.spj_code, spj_version=self.spj_version) return try: s = TimeoutServerProxy("http://" + judge_server.ip + ":" + str(judge_server.port), timeout=30) data = s.run(judge_server.token, self.submission.id, self.submission.language, self.submission.code, self.time_limit, self.memory_limit, self.test_case_id, self.spj, self._none_to_false(self.spj_language), self._none_to_false(self.spj_code), self._none_to_false(self.spj_version)) # 编译错误 if data["code"] == 1: self.submission.result = result["compile_error"] self.submission.info = data["data"]["error"] # system error elif data["code"] == 2: self.submission.result = result["system_error"] self.submission.info = data["data"]["error"] elif data["code"] == 0: self.submission.result = data["data"]["result"] self.submission.info = json.dumps(data["data"]["info"]) self.submission.accepted_answer_time = data["data"]["accepted_answer_time"] except Exception as e: self.submission.result = result["system_error"] self.submission.info = str(e) + " help: https://github.com/QingdaoU/OnlineJudge/wiki/FAQ" finally: self.release_judge_instance(judge_server.id) self.submission.judge_end_time = int(time.time() * 1000) self.submission.save(update_fields=["judge_start_time", "result", "info", "accepted_answer_time", "judge_end_time"]) if self.submission.contest_id: self.update_contest_problem_status() else: self.update_problem_status() with transaction.atomic(): waiting_submissions = JudgeWaitingQueue.objects.select_for_update().all() if waiting_submissions.exists(): # 防止循环依赖 from submission.tasks import _judge waiting_submission = waiting_submissions.first() waiting_submission.delete() _judge.delay(submission_id=waiting_submission.submission_id, time_limit=waiting_submission.time_limit, memory_limit=waiting_submission.memory_limit, test_case_id=waiting_submission.test_case_id, spj=waiting_submission.spj, spj_language=waiting_submission.spj_language, spj_code=waiting_submission.spj_code, spj_version=waiting_submission.spj_version)