def grade(self, case): result = Result(case) input = case.input_data() # cache generator data self._current_proc = self.binary.launch(time=self.problem.time_limit, memory=self.problem.memory_limit, pipe_stderr=True, unbuffered=case.config.unbuffered, io_redirects=case.io_redirects()) error = self._interact_with_process(case, result, input) process = self._current_proc result.max_memory = process.max_memory or 0.0 result.execution_time = process.execution_time or 0.0 result.r_execution_time = process.r_execution_time or 0.0 # Translate status codes/process results into Result object for status codes self.set_result_flag(process, result) check = self.check_result(case, result) # checkers must either return a boolean (True: full points, False: 0 points) # or a CheckerResult, so convert to CheckerResult if it returned bool if not isinstance(check, CheckerResult): check = CheckerResult(check, case.points if check else 0.0) result.result_flag |= [Result.WA, Result.AC][check.passed] result.points = check.points self.update_feedback(check, error, process, result) return result
def grade(self, case): result = Result(case) case.input_data() # cache generator data self._current_proc = self.binary.launch(time=self.problem.time_limit, memory=self.problem.memory_limit, pipe_stderr=True, unbuffered=case.config.unbuffered) error = self._interact_with_process(case, result) process = self._current_proc result.max_memory = process.max_memory or 0.0 result.execution_time = process.execution_time or 0.0 result.r_execution_time = process.r_execution_time or 0.0 # checkers might crash if any data is None, so force at least empty string check = case.checker()(result.proc_output or '', case.output_data() or '', submission_source=self.source, judge_input=case.input_data() or '', point_value=case.points) # checkers must either return a boolean (True: full points, False: 0 points) # or a CheckerResult, so convert to CheckerResult if it returned bool if not isinstance(check, CheckerResult): check = CheckerResult(check, case.points if check else 0.0) result.result_flag |= [Result.WA, Result.AC][check.passed] # Translate status codes/process results into Result object for status codes if process.returncode > 0: # print>> sys.stderr, 'Exited with error: %d' % process.returncode result.result_flag |= Result.IR if process.returncode < 0: # None < 0 == True # if process.returncode is not None: # print>> sys.stderr, 'Killed by signal %d' % -process.returncode result.result_flag |= Result.RTE # Killed by signal if process.tle: result.result_flag |= Result.TLE if process.mle: result.result_flag |= Result.MLE if result.result_flag & ~Result.WA: check.points = 0 result.points = check.points result.feedback = (check.feedback or (process.feedback if hasattr(process, 'feedback') else getattr(self.binary, 'get_feedback', lambda x, y: '')(error, result))) if not result.feedback and hasattr(process, 'signal') and process.signal and result.get_main_code() in [Result.IR, Result.RTE]: result.feedback = strsignal(process.signal) return result
def grade(self, case): result = Result(case) input = case.input_data() # cache generator data self._current_proc = self.binary.launch(time=self.problem.time_limit, memory=self.problem.memory_limit, symlinks=case.config.symlinks, pipe_stderr=True, wall_time=case.config.wall_time_factor * self.problem.time_limit) error = self._interact_with_process(case, result, input) process = self._current_proc result.max_memory = process.max_memory or 0.0 result.execution_time = process.execution_time or 0.0 result.r_execution_time = process.r_execution_time or 0.0 # Translate status codes/process results into Result object for status codes self.set_result_flag(process, result) check = self.check_result(case, result) # checkers must either return a boolean (True: full points, False: 0 points) # or a CheckerResult, so convert to CheckerResult if it returned bool if not isinstance(check, CheckerResult): check = CheckerResult(check, case.points if check else 0.0) result.result_flag |= [Result.WA, Result.AC][check.passed] result.points = check.points result.extended_feedback = check.extended_feedback self.update_feedback(check, error, process, result) case.free_data() # Where CPython has reference counting and a GC, PyPy only has a GC. This means that while CPython # will have freed any (usually massive) generated data from the line above by reference counting, it might # - and probably still is - in memory by now. We need to be able to fork() immediately, which has a good chance # of failing if there's not a lot of swap space available. # # We don't really have a way to force the generated data to disappear, so calling a gc here is the best # chance we have. if platform.python_implementation() == 'PyPy': gc.collect() return result