Spaces:
Sleeping
Sleeping
Experimenting with how I return results
Browse files- restrictedpython_code_eval.py +10 -10
restrictedpython_code_eval.py
CHANGED
@@ -433,7 +433,7 @@ def _check_correctness(check_program, timeout, task_id, completion_id,
|
|
433 |
the results later even if execution finishes asynchronously.
|
434 |
"""
|
435 |
manager = multiprocessing.Manager()
|
436 |
-
result = manager.
|
437 |
|
438 |
args = (
|
439 |
check_program, result, timeout,
|
@@ -449,12 +449,12 @@ def _check_correctness(check_program, timeout, task_id, completion_id,
|
|
449 |
p.kill()
|
450 |
|
451 |
if not result:
|
452 |
-
result
|
453 |
|
454 |
out_dict = dict(
|
455 |
task_id=task_id,
|
456 |
-
passed=result[
|
457 |
-
result=
|
458 |
completion_id=completion_id,
|
459 |
)
|
460 |
|
@@ -613,18 +613,18 @@ def _unsafe_execute(check_program, result, timeout,
|
|
613 |
byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class)
|
614 |
exec(byte_code, exec_globals, additional_locals)
|
615 |
|
616 |
-
result
|
617 |
|
618 |
except EOFError:
|
619 |
-
result
|
620 |
except TimeoutException:
|
621 |
-
result
|
622 |
except BaseException as e:
|
623 |
-
result
|
624 |
-
result
|
625 |
|
626 |
if return_output and output_variable in additional_locals: # type: ignore
|
627 |
-
result
|
628 |
|
629 |
# Needed for cleaning up.
|
630 |
shutil.rmtree = rmtree
|
|
|
433 |
the results later even if execution finishes asynchronously.
|
434 |
"""
|
435 |
manager = multiprocessing.Manager()
|
436 |
+
result = manager.dict()
|
437 |
|
438 |
args = (
|
439 |
check_program, result, timeout,
|
|
|
449 |
p.kill()
|
450 |
|
451 |
if not result:
|
452 |
+
result['result'] = "Result evaluates to False (probably timed out)"
|
453 |
|
454 |
out_dict = dict(
|
455 |
task_id=task_id,
|
456 |
+
passed=result['result'] == "passed",
|
457 |
+
result=dict(result),
|
458 |
completion_id=completion_id,
|
459 |
)
|
460 |
|
|
|
613 |
byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class)
|
614 |
exec(byte_code, exec_globals, additional_locals)
|
615 |
|
616 |
+
result['result'] = "passed"
|
617 |
|
618 |
except EOFError:
|
619 |
+
result['result'] = "EOF error"
|
620 |
except TimeoutException:
|
621 |
+
result['result'] = "timed out"
|
622 |
except BaseException as e:
|
623 |
+
result['result'] = f"failed ({type(e)}): {str(e)}"
|
624 |
+
result['exception'] = e
|
625 |
|
626 |
if return_output and output_variable in additional_locals: # type: ignore
|
627 |
+
result['output_variable'] = additional_locals[output_variable] # type: ignore
|
628 |
|
629 |
# Needed for cleaning up.
|
630 |
shutil.rmtree = rmtree
|