當前位置: 首頁>>代碼示例>>Python>>正文


Python Result.result_flag方法代碼示例

本文整理匯總了Python中result.Result.result_flag方法的典型用法代碼示例。如果您正苦於以下問題:Python Result.result_flag方法的具體用法?Python Result.result_flag怎麽用?Python Result.result_flag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在result.Result的用法示例。


在下文中一共展示了Result.result_flag方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import result_flag [as 別名]
    def run(self, executor, init_data, check_func, problem_id, short_circuit=False, time=2, memory=65536,
            source_code=None, interactive=False):
        """
        Executes a submission in standard (static) mode.
        :param executor:
            Executor to launch the submission program.
        :param init_data:
            The problem initialization data.
        :param check_func:
            Callback to check validity of the submission program output.
        :param problem_id:
            The problem code.
        :param short_circuit:
            Whether to short-circuit batch testcases.
        :param time:
            Time limit for submission program, in seconds.
        :param memory:
            Memory limit for submission program, in kilobytes.
        :param interactive:
            Boolean to indicate whether this needs a custom grader and interactor.
        :return:
            A Result instance representing the execution result of the submission program.
        """
        output_prefix_length = init_data.get('output_prefix_length', 32)
        unbuffered = init_data.get('unbuffered', False)
        time_adjust = init_data.get('time_adjust', 1.0)
        forward_test_cases = []
        for case in init_data['test_cases']:
            if isinstance(case, dict):
                if 'data' in case:
                    # Data is batched, with multiple subcases for each parent case
                    # If one subcase fails, the main case fails too
                    subcases = [(subcase.get('in', None), subcase.get('out', None)) for subcase in case['data']]
                    case = BatchedTestCase(subcases, int(case.get('points', 0)), output_length=case.get('output_prefix_length', output_prefix_length))
                else:
                    case = TestCase(case.get('in', None), case.get('out', None), int(case.get('points', 0)), case.get('output_prefix_length', output_prefix_length))
            else:
                # Not sure what this does, but it was in run_interactive
                case = (None, None, int(case))
            forward_test_cases.append(case)

        if interactive:
            if 'grader' not in init_data:
                raise IOError('no grader specified')
            grader_path = os.path.join(get_problem_root(problem_id), init_data['grader'])
            if not os.path.exists(grader_path):
                raise IOError('grader does not exist')

            try:
                interactive_grader = load_module_from_file(grader_path)
            except:
                traceback.print_exc()
                raise IOError('could not load grader module')
        else:
            interactive_grader = None

        topen = self._resolve_open_call(init_data, problem_id, forward_test_cases)

        self.packet_manager.begin_grading_packet()
        case_number = 1
        short_circuited = False
        try:
            for test_case in forward_test_cases:
                if isinstance(test_case, BatchedTestCase):
                    self.packet_manager.begin_batch_packet()
                for input_file, output_file, point_value, output_length in test_case:
                    if self._terminate_grading:
                        raise TerminateGrading()
                    result = Result()
                    if short_circuited:
                        # A previous subtestcase failed so we're allowed to break early
                        result.result_flag = Result.SC
                        check = CheckerResult(False, 0)
                        feedback = None
                    else:
                        _input_data = topen(input_file) if input_file else ''
                        if hasattr(_input_data, 'read'):
                            try:
                                input_data = _input_data.read()
                            finally:
                                _input_data.close()
                        else:
                            input_data = _input_data
                        if input_data:
                            input_data = input_data.replace('\r\n', '\n')  # .replace('\r', '\n')

                        _output_data = topen(output_file) if output_file else ''
                        if hasattr(_output_data, 'read'):
                            try:
                                output_data = _output_data.read()
                            finally:
                                _output_data.close()
                        else:
                            output_data = _output_data
                        if output_data:
                            output_data = output_data.replace('\r\n', '\n')  # .replace('\r', '\n')

                        # Launch a process for the current test case
                        self.current_proc = executor.launch(time=time, memory=memory, pipe_stderr=True, unbuffered=unbuffered)

#.........這裏部分代碼省略.........
開發者ID:rayeya,項目名稱:judge,代碼行數:103,代碼來源:judge.py


注:本文中的result.Result.result_flag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。