DebugClients/Python/ThreadExtension.py

branch
debugger speed
changeset 5209
cd058aa6af37
parent 5208
aa8045780ce4
child 5221
960afd19c1b6
diff -r aa8045780ce4 -r cd058aa6af37 DebugClients/Python/ThreadExtension.py
--- a/DebugClients/Python/ThreadExtension.py	Thu Oct 06 22:51:04 2016 +0200
+++ b/DebugClients/Python/ThreadExtension.py	Fri Oct 07 22:50:48 2016 +0200
@@ -32,6 +32,7 @@
         Constructor
         """
         self.threadNumber = 1
+        self.enableImportHooks = True
         self._original_start_new_thread = None
         
         self.clientLock = threading.RLock()
@@ -54,6 +55,8 @@
         del sys.modules[self.threadModName]
         del sys.modules['threading']
         
+        sys.meta_path.insert(0, self)
+        
         # provide a hook to perform a hard breakpoint
         # Use it like this:
         # if hasattr(sys, 'breakpoint): sys.breakpoint()
@@ -79,7 +82,7 @@
             ident = _thread.get_ident()
             name = 'MainThread'
             newThread = self.mainThread
-            newThread._mainThread = True
+            newThread.isMainThread = True
             if self.debugging:
                 sys.setprofile(newThread.profile)
             
@@ -97,15 +100,16 @@
 
         return ident
     
-    def threadTerminated(self, dbgThread):
+    def threadTerminated(self, threadId):
         """
         Public method called when a DebugThread has exited.
         
-        @param dbgThread the DebugThread that has exited
+        @param threadId id of the DebugThread that has exited
+        @type int
         """
         self.lockClient()
         try:
-            del self.threads[dbgThread.get_ident()]
+            del self.threads[threadId]
         except KeyError:
             pass
         finally:
@@ -142,10 +146,10 @@
         """
         try:
             self.lockClient()
-            if id is None or id not in self.threads:
+            if id is None:
                 self.currentThread = None
             else:
-                self.currentThread = self.threads[id]
+                self.currentThread = self.threads.get(id)
         finally:
             self.unlockClient()
     
@@ -180,6 +184,46 @@
             "currentID": currentId,
             "threadList": threadList,
         })
+    
+    def find_module(self, fullname, path=None):
+        """
+        Public method returning the module loader.
+        
+        @param fullname name of the module to be loaded
+        @type str
+        @param path path to resolve the module name
+        @type str
+        @return module loader object
+        @rtype object
+        """
+        if fullname in sys.modules or not self.debugging:
+            return None
+        if fullname == self.threadModName and self.enableImportHooks:
+            # Disable hook to be able to import original module
+            self.enableImportHooks = False
+            return self
+        
+        return None
+    
+    def load_module(self, fullname):
+        """
+        Public method to load a module.
+        
+        @param fullname name of the module to be loaded
+        @type str
+        @return reference to the loaded module
+        @rtype module
+        """
+        module = __import__(fullname)
+        sys.modules[fullname] = module
+        if (fullname == self.threadModName and
+                self._original_start_new_thread is None):
+            # make thread hooks available to system
+            self._original_start_new_thread = module.start_new_thread
+            module.start_new_thread = self.attachThread
+        
+        self.enableImportHooks = True
+        return module
 
 
 #

eric ide

mercurial