summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/python_session.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/server/python_session.py b/server/python_session.py
index 33fe7cc..62fcbf8 100644
--- a/server/python_session.py
+++ b/server/python_session.py
@@ -172,9 +172,17 @@ def _run_exec(conn, code, expr=None, stdin=''):
if expr:
result = eval(expr, env)
except Exception as ex:
- # Exception is not JSON serializable, so return traceback as string.
+ # Exception is not JSON serializable, so return traceback as string
+ # (without the first entry, which is this function).
import traceback
- exc = traceback.format_exc()
+ e_type, e_value, e_tb = sys.exc_info()
+ stack = traceback.extract_tb(e_tb)
+ exc = ''.join(
+ ['Traceback (most recent call last):\n'] +
+ [' line {}, in {}\n'.format(lineno, name) + (line+'\n' if line else '')
+ for filename, lineno, name, line in stack[1:]] +
+ traceback.format_exception_only(e_type, e_value)
+ ).rstrip()
finally:
out = sys.stdout.getvalue()
err = sys.stderr.getvalue()