DebugClients/Python/ThreadExtension.py

changeset 5240
71c51aae2f4e
parent 5228
4332a6751b14
child 5269
0e96e1557c45
equal deleted inserted replaced
5239:27f56dc07b5b 5240:71c51aae2f4e
7 Module implementing an import hook patching thread modules to get debugged too. 7 Module implementing an import hook patching thread modules to get debugged too.
8 """ 8 """
9 9
10 import os.path 10 import os.path
11 import sys 11 import sys
12 import importlib
12 13
13 if sys.version_info[0] == 2: 14 if sys.version_info[0] == 2:
14 import thread as _thread 15 import thread as _thread
15 else: 16 else:
16 import _thread 17 import _thread
267 @param fullname name of the module to be loaded 268 @param fullname name of the module to be loaded
268 @type str 269 @type str
269 @return reference to the loaded module 270 @return reference to the loaded module
270 @rtype module 271 @rtype module
271 """ 272 """
272 module = __import__(fullname) 273 module = importlib.import_module(fullname)
273 sys.modules[fullname] = module 274 sys.modules[fullname] = module
274 if (fullname == self.threadModName and 275 if (fullname == self.threadModName and
275 self._original_start_new_thread is None): 276 self._original_start_new_thread is None):
276 # make thread hooks available to system 277 # make thread hooks available to system
277 self._original_start_new_thread = module.start_new_thread 278 self._original_start_new_thread = module.start_new_thread
278 module.start_new_thread = self.attachThread 279 module.start_new_thread = self.attachThread
279 elif fullname in ['PyQt4.QtCore', 'PyQt5.QtCore', 280 elif fullname in ['PyQt4.QtCore', 'PyQt5.QtCore',
280 'PySide.QtCore'] and self._qtThread is None: 281 'PySide.QtCore'] and self._qtThread is None:
281 self._qtThread = module.QtCore.QThread 282 self._qtThread = module.QThread
282 # _debugClient as a class attribute can't be accessed in following 283 # _debugClient as a class attribute can't be accessed in following
283 # class. Therefore we need a global variable. 284 # class. Therefore we need a global variable.
284 _debugClient = self 285 _debugClient = self
285 286
286 class QThreadWrapper(module.QtCore.QThread): 287 class QThreadWrapper(module.QThread):
287 __qtThreadNumber = 1 288 __qtThreadNumber = 1
288 289
289 def __init__(self, *args, **kwargs): 290 def __init__(self, *args, **kwargs):
290 # Overwrite the provided run method with our own, to 291 # Overwrite the provided run method with our own, to
291 # intercept the thread creation by Qt 292 # intercept the thread creation by Qt

eric ide

mercurial