Sun, 19 Feb 2017 22:13:48 +0100
Improved atexit handling.
DebugClients/Python/DebugBase.py | file | annotate | diff | comparison | revisions | |
DebugClients/Python/DebugClientBase.py | file | annotate | diff | comparison | revisions |
--- a/DebugClients/Python/DebugBase.py Sat Feb 18 21:54:09 2017 +0100 +++ b/DebugClients/Python/DebugBase.py Sun Feb 19 22:13:48 2017 +0100 @@ -428,7 +428,7 @@ sys.settrace(None) sys.setprofile(None) - def run(self, cmd, globals=None, locals=None): + def run(self, cmd, globals=None, locals=None, debug=True): """ Public method to start a given command under debugger control. @@ -446,10 +446,12 @@ if locals is None: locals = globals - sys.settrace(self.trace_dispatch) if not isinstance(cmd, types.CodeType): cmd = compile(cmd, "<string>", "exec") + if debug: + sys.settrace(self.trace_dispatch) + try: exec(cmd, globals, locals) atexit._run_exitfuncs()
--- a/DebugClients/Python/DebugClientBase.py Sat Feb 18 21:54:09 2017 +0100 +++ b/DebugClients/Python/DebugClientBase.py Sun Feb 19 22:13:48 2017 +0100 @@ -494,8 +494,7 @@ code = self.__compileFileSource(self.running) if code: sys.setprofile(self.callTraceEnabled) - res = self.mainThread.run(code, self.debugMod.__dict__) - self.progTerminated(res) + self.mainThread.run(code, self.debugMod.__dict__, debug=True) elif method == "RequestRun": sys.argv = [] @@ -529,13 +528,7 @@ res = 0 code = self.__compileFileSource(self.running) if code: - try: - exec(code, self.debugMod.__dict__) - except SystemExit as exc: - res = exc.code - atexit._run_exitfuncs() - self.writestream.flush() - self.progTerminated(res) + self.mainThread.run(code, self.debugMod.__dict__, debug=False) elif method == "RequestCoverage": from coverage import coverage @@ -567,17 +560,10 @@ code = self.__compileFileSource(sys.argv[0]) if code: self.running = sys.argv[0] - res = 0 self.cover.start() - try: - exec(code, self.debugMod.__dict__) - except SystemExit as exc: - res = exc.code - atexit._run_exitfuncs() + self.mainThread.run(code, self.debugMod.__dict__, debug=False) self.cover.stop() self.cover.save() - self.writestream.flush() - self.progTerminated(res) elif method == "RequestProfile": sys.setprofile(None) @@ -618,12 +604,15 @@ res = 0 try: self.prof.run(script) + atexit._run_exitfuncs() except SystemExit as exc: res = exc.code - - atexit._run_exitfuncs() + atexit._run_exitfuncs() + except Exception: + excinfo = sys.exc_info() + self.__unhandled_exception(*excinfo) + self.prof.save() - self.writestream.flush() self.progTerminated(res) elif method == "ExecuteStatement":