DebugClients/Python/ThreadExtension.py

branch
debugger fine grinding
changeset 5544
5a90f78a73c9
parent 5389
9b1c800daff3
child 5552
313a91a38aed
equal deleted inserted replaced
5543:4e2ab5215bcf 5544:5a90f78a73c9
33 Constructor 33 Constructor
34 """ 34 """
35 self.threadNumber = 1 35 self.threadNumber = 1
36 self.enableImportHooks = True 36 self.enableImportHooks = True
37 self._original_start_new_thread = None 37 self._original_start_new_thread = None
38 self.threadingAttached = False
38 self._qtThread = None 39 self._qtThread = None
39 40
40 self.clientLock = threading.RLock() 41 self.clientLock = threading.RLock()
41 42
42 # dictionary of all threads running {id: DebugBase} 43 # dictionary of all threads running {id: DebugBase}
248 """ 249 """
249 if fullname in sys.modules or not self.debugging: 250 if fullname in sys.modules or not self.debugging:
250 return None 251 return None
251 252
252 if fullname in [self.threadModName, 'PyQt4.QtCore', 'PyQt5.QtCore', 253 if fullname in [self.threadModName, 'PyQt4.QtCore', 'PyQt5.QtCore',
253 'PySide.QtCore'] and self.enableImportHooks: 254 'PySide.QtCore', 'PySide2.QtCore',
255 'threading'] and self.enableImportHooks:
254 # Disable hook to be able to import original module 256 # Disable hook to be able to import original module
255 self.enableImportHooks = False 257 self.enableImportHooks = False
256 return self 258 return self
257 259
258 return None 260 return None
271 if (fullname == self.threadModName and 273 if (fullname == self.threadModName and
272 self._original_start_new_thread is None): 274 self._original_start_new_thread is None):
273 # make thread hooks available to system 275 # make thread hooks available to system
274 self._original_start_new_thread = module.start_new_thread 276 self._original_start_new_thread = module.start_new_thread
275 module.start_new_thread = self.attachThread 277 module.start_new_thread = self.attachThread
276 elif fullname in ['PyQt4.QtCore', 'PyQt5.QtCore', 278
277 'PySide.QtCore'] and self._qtThread is None: 279 # Add hook for threading.run()
280 elif (fullname == "threading" and self.threadingAttached is False):
281 self.threadingAttached = True
282
283 # _debugClient as a class attribute can't be accessed in following
284 # class. Therefore we need a global variable.
285 _debugClient = self
286
287 def _bootstrap(self, run):
288 newThread = _debugClient.threads[self.ident]
289 newThread.name = self.name
290 # see DebugBase.bootstrap
291 sys.settrace(newThread.trace_dispatch)
292 try:
293 run()
294 except Exception:
295 excinfo = sys.exc_info()
296 newThread.user_exception(excinfo, True)
297
298 class ThreadWrapper(module.Thread):
299
300 def __init__(self, *args, **kwargs):
301 # Overwrite the provided run method with our own, to
302 # intercept the thread creation by threading.Thread
303 self.run = lambda s=self, run=self.run: _bootstrap(s, run)
304
305 super(ThreadWrapper, self).__init__(*args, **kwargs)
306
307 module.Thread = ThreadWrapper
308
309 elif (fullname in ['PyQt4.QtCore', 'PyQt5.QtCore',
310 'PySide.QtCore', 'PySide2.QtCore'] and
311 self._qtThread is None):
278 self._qtThread = module.QThread 312 self._qtThread = module.QThread
279 # _debugClient as a class attribute can't be accessed in following 313 # _debugClient as a class attribute can't be accessed in following
280 # class. Therefore we need a global variable. 314 # class. Therefore we need a global variable.
281 _debugClient = self 315 _debugClient = self
282 316

eric ide

mercurial