diff options
author | Prabhu Ramachandran | 2011-11-13 23:43:26 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2011-11-13 23:43:26 +0530 |
commit | fb7257f168f8e3187dccf0bb2d0ac88418028e17 (patch) | |
tree | baa1683be12b730ab9f2662cab448d9d22969c70 | |
parent | bc343c26cf3aac699c08129034b41317bac16f76 (diff) | |
download | online_test-fb7257f168f8e3187dccf0bb2d0ac88418028e17.tar.gz online_test-fb7257f168f8e3187dccf0bb2d0ac88418028e17.tar.bz2 online_test-fb7257f168f8e3187dccf0bb2d0ac88418028e17.zip |
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.
-rwxr-xr-x | python_server.py | 15 |
1 files changed, 13 insertions, 2 deletions
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, '<string>', mode='exec') g = {} exec submitted in g _tests = compile(test_code, '<string>', 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 |