From fb7257f168f8e3187dccf0bb2d0ac88418028e17 Mon Sep 17 00:00:00 2001 From: Prabhu Ramachandran Date: Sun, 13 Nov 2011 23:43:26 +0530 Subject: Revert last commit. "ENH: Improved traceback reporting from server. " Strangely, the reporting by this is not as good as my hand-rolled code. This reverts commit bc343c26cf3aac699c08129034b41317bac16f76. --- python_server.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'python_server.py') diff --git a/python_server.py b/python_server.py index b90655b..1670f90 100755 --- a/python_server.py +++ b/python_server.py @@ -3,6 +3,7 @@ and returns the output. It *should* be run as root and will run as the user 'nobody' so as to minimize any damange by errant code. """ +import sys import traceback from SimpleXMLRPCServer import SimpleXMLRPCServer import pwd @@ -31,18 +32,28 @@ def run_code(answer, test_code, in_dir=None): if in_dir is not None and isdir(in_dir): os.chdir(in_dir) + success = False + tb = None try: submitted = compile(answer, '', mode='exec') g = {} exec submitted in g _tests = compile(test_code, '', mode='exec') exec _tests in g + except AssertionError: + type, value, tb = sys.exc_info() + info = traceback.extract_tb(tb) + fname, lineno, func, text = info[-1] + text = str(test_code).splitlines()[lineno-1] + err = "{0} {1} in: {2}".format(type.__name__, str(value), text) except: - success = False - err = traceback.format_exc(limit=1) + type, value = sys.exc_info()[:2] + err = "Error: {0}".format(repr(value)) else: success = True err = 'Correct answer' + finally: + del tb return success, err -- cgit