Exemplo n.º 1
0
 def _await_result(self):
     # TODO cancel if result was cancelled by a newer handle_entry
     result = None
     while result is None:
         timeout = 10 if self.fresh_process else 3
         try:
             result = self.result_queue.get(timeout=timeout)
             assert (result is None) == self.fresh_process
             self.fresh_process = False
         except queue.Empty:
             alive = self.process.is_alive()
             log.info(f"Process {alive=}")
             if alive:
                 self.process.terminate()
             self.start_process()
             result = make_result(
                 output_parts=[
                     dict(color='red', text='The process died.\n'),
                     dict(color='red',
                          text='Your code probably took too long.\n'),
                     dict(color='red',
                          text='Maybe you have an infinite loop?\n'),
                 ],
                 output='The process died.',
             )
     return result
Exemplo n.º 2
0
 def _await_result(self):
     # TODO cancel if result was cancelled by a newer handle_entry
     result = None
     while result is None:
         if simple_settings.Root.SET_LIMITS:
             timeout = 10 if self.fresh_process else 3
         else:
             timeout = None
         try:
             result = self.result_queue.get(timeout=timeout)
             assert (result is None) == self.fresh_process
             self.fresh_process = False
         except queue.Empty:
             self.start_process()
             result = make_result(
                 output_parts=[
                     dict(color='red', text='The process died.\n'),
                     dict(color='red',
                          text='Your code probably took too long.\n'),
                     dict(color='red',
                          text='Maybe you have an infinite loop?\n'),
                 ],
                 output='The process died.',
             )
     return result
Exemplo n.º 3
0
def run_code(entry, input_queue, result_queue):
    def readline():
        result_queue.put(make_result(awaiting_input=True))
        return input_queue.get()

    sys.stdin.readline = readline

    orig_stdout = sys.stdout
    orig_stderr = sys.stderr
    try:
        sys.stdout = output_buffer.stdout
        sys.stderr = output_buffer.stderr
        birdseye_objects = runner(entry['source'], entry['input'])
    finally:
        sys.stdout = orig_stdout
        sys.stderr = orig_stderr

    messages = []
    passed = False
    output = output_buffer.string()

    if entry['step_name'] != "final_text":
        page = pages[entry['page_slug']]
        step_result = page.check_step(entry, output, console)
        if isinstance(step_result, dict):
            passed = step_result.get("passed", False)
            messages = step_result.get("messages", [])
            if "message" in step_result:
                messages.append(step_result["message"])
        else:
            passed = step_result

    result_queue.put(
        make_result(
            passed=passed,
            messages=messages,
            output=output,
            birdseye_objects=birdseye_objects,
        ))
Exemplo n.º 4
0
 def readline():
     result_queue.put(make_result(awaiting_input=True))
     return input_queue.get()