DebugClients/Python3/DebugClientBase.py

changeset 2371
72e2f353f34b
parent 2302
f29e9405c851
child 2376
a0409e65bd81
--- a/DebugClients/Python3/DebugClientBase.py	Fri Jan 25 18:20:16 2013 +0100
+++ b/DebugClients/Python3/DebugClientBase.py	Sat Jan 26 12:41:53 2013 +0100
@@ -16,6 +16,7 @@
 import time
 import imp
 import re
+import atexit
 
 
 import DebugProtocol
@@ -608,12 +609,23 @@
                     self.cover.erase()
                 sys.modules['__main__'] = self.debugMod
                 self.debugMod.__dict__['__file__'] = sys.argv[0]
-                self.cover.start()
-                exec(open(sys.argv[0], encoding=self.__coding).read(),
-                     self.debugMod.__dict__)
-                self.cover.stop()
-                self.cover.save()
-                self.writestream.flush()
+                fp = open(sys.argv[0], encoding=self.__coding)
+                try:
+                    script = fp.read()
+                finally:
+                    fp.close()
+                if script:
+                    if not script.endswith('\n'):
+                        script += '\n'
+                    code = compile(script, sys.argv[0], 'exec')
+                    self.cover.start()
+                    try:
+                        exec(code, self.debugMod.__dict__)
+                    except SystemExit:
+                        atexit._run_exitfuncs()
+                    self.cover.stop()
+                    self.cover.save()
+                    self.writestream.flush()
                 return
 
             if cmd == DebugProtocol.RequestShutdown:

eric ide

mercurial