51 self.threadModName = '_thread' |
52 self.threadModName = '_thread' |
52 |
53 |
53 # reset already imported thread module to apply hooks at next import |
54 # reset already imported thread module to apply hooks at next import |
54 del sys.modules[self.threadModName] |
55 del sys.modules[self.threadModName] |
55 del sys.modules['threading'] |
56 del sys.modules['threading'] |
|
57 |
|
58 sys.meta_path.insert(0, self) |
56 |
59 |
57 # provide a hook to perform a hard breakpoint |
60 # provide a hook to perform a hard breakpoint |
58 # Use it like this: |
61 # Use it like this: |
59 # if hasattr(sys, 'breakpoint): sys.breakpoint() |
62 # if hasattr(sys, 'breakpoint): sys.breakpoint() |
60 sys.breakpoint = self.set_trace |
63 sys.breakpoint = self.set_trace |
77 """ |
80 """ |
78 if mainThread: |
81 if mainThread: |
79 ident = _thread.get_ident() |
82 ident = _thread.get_ident() |
80 name = 'MainThread' |
83 name = 'MainThread' |
81 newThread = self.mainThread |
84 newThread = self.mainThread |
82 newThread._mainThread = True |
85 newThread.isMainThread = True |
83 if self.debugging: |
86 if self.debugging: |
84 sys.setprofile(newThread.profile) |
87 sys.setprofile(newThread.profile) |
85 |
88 |
86 else: |
89 else: |
87 newThread = DebugBase(self) |
90 newThread = DebugBase(self) |
95 |
98 |
96 self.threads[ident] = newThread |
99 self.threads[ident] = newThread |
97 |
100 |
98 return ident |
101 return ident |
99 |
102 |
100 def threadTerminated(self, dbgThread): |
103 def threadTerminated(self, threadId): |
101 """ |
104 """ |
102 Public method called when a DebugThread has exited. |
105 Public method called when a DebugThread has exited. |
103 |
106 |
104 @param dbgThread the DebugThread that has exited |
107 @param threadId id of the DebugThread that has exited |
|
108 @type int |
105 """ |
109 """ |
106 self.lockClient() |
110 self.lockClient() |
107 try: |
111 try: |
108 del self.threads[dbgThread.get_ident()] |
112 del self.threads[threadId] |
109 except KeyError: |
113 except KeyError: |
110 pass |
114 pass |
111 finally: |
115 finally: |
112 self.unlockClient() |
116 self.unlockClient() |
113 |
117 |
178 |
182 |
179 self.sendJsonCommand("ResponseThreadList", { |
183 self.sendJsonCommand("ResponseThreadList", { |
180 "currentID": currentId, |
184 "currentID": currentId, |
181 "threadList": threadList, |
185 "threadList": threadList, |
182 }) |
186 }) |
|
187 |
|
188 def find_module(self, fullname, path=None): |
|
189 """ |
|
190 Public method returning the module loader. |
|
191 |
|
192 @param fullname name of the module to be loaded |
|
193 @type str |
|
194 @param path path to resolve the module name |
|
195 @type str |
|
196 @return module loader object |
|
197 @rtype object |
|
198 """ |
|
199 if fullname in sys.modules or not self.debugging: |
|
200 return None |
|
201 if fullname == self.threadModName and self.enableImportHooks: |
|
202 # Disable hook to be able to import original module |
|
203 self.enableImportHooks = False |
|
204 return self |
|
205 |
|
206 return None |
|
207 |
|
208 def load_module(self, fullname): |
|
209 """ |
|
210 Public method to load a module. |
|
211 |
|
212 @param fullname name of the module to be loaded |
|
213 @type str |
|
214 @return reference to the loaded module |
|
215 @rtype module |
|
216 """ |
|
217 module = __import__(fullname) |
|
218 sys.modules[fullname] = module |
|
219 if (fullname == self.threadModName and |
|
220 self._original_start_new_thread is None): |
|
221 # make thread hooks available to system |
|
222 self._original_start_new_thread = module.start_new_thread |
|
223 module.start_new_thread = self.attachThread |
|
224 |
|
225 self.enableImportHooks = True |
|
226 return module |
183 |
227 |
184 |
228 |
185 # |
229 # |
186 # eflag: noqa = M702 |
230 # eflag: noqa = M702 |