DebugClients/Python/ThreadExtension.py

branch
maintenance
changeset 6206
a02b03b7bfec
parent 6050
25a4ddb25ca4
parent 6196
7135a692e43e
child 6646
51eefa621de4
equal deleted inserted replaced
6205:ad8ed15f90e5 6206:a02b03b7bfec
319 newThread.user_exception(excinfo, True) 319 newThread.user_exception(excinfo, True)
320 finally: 320 finally:
321 sys.settrace(None) 321 sys.settrace(None)
322 322
323 class ThreadWrapper(module.Thread): 323 class ThreadWrapper(module.Thread):
324 """ Wrapper class for threading.Thread. """ 324 """
325 325 Wrapper class for threading.Thread.
326 """
326 def __init__(self, *args, **kwargs): 327 def __init__(self, *args, **kwargs):
328 """
329 Constructor
330 """
327 # Overwrite the provided run method with our own, to 331 # Overwrite the provided run method with our own, to
328 # intercept the thread creation by threading.Thread 332 # intercept the thread creation by threading.Thread
329 self.run = lambda s=self, run=self.run: _bootstrap(s, run) 333 self.run = lambda s=self, run=self.run: _bootstrap(s, run)
330 334
331 super(ThreadWrapper, self).__init__(*args, **kwargs) 335 super(ThreadWrapper, self).__init__(*args, **kwargs)
332 336
333 module.Thread = ThreadWrapper 337 module.Thread = ThreadWrapper
338
339 # Special handling of threading.(_)Timer
340 if sys.version_info[0] == 2:
341 timer = module._Timer
342 else:
343 timer = module.Timer
344
345 class TimerWrapper(timer, ThreadWrapper):
346 """
347 Wrapper class for threading.(_)Timer.
348 """
349 def __init__(self, interval, function, *args, **kwargs):
350 """
351 Constructor
352 """
353 super(TimerWrapper, self).__init__(
354 interval, function, *args, **kwargs)
355
356 if sys.version_info[0] == 2:
357 module._Timer = TimerWrapper
358 else:
359 module.Timer = TimerWrapper
334 360
335 # Add hook for *.QThread 361 # Add hook for *.QThread
336 elif (fullname in ['PyQt4.QtCore', 'PyQt5.QtCore', 362 elif (fullname in ['PyQt4.QtCore', 'PyQt5.QtCore',
337 'PySide.QtCore', 'PySide2.QtCore'] and 363 'PySide.QtCore', 'PySide2.QtCore'] and
338 self.qtThreadAttached is False): 364 self.qtThreadAttached is False):
373 newThread.user_exception(excinfo, True) 399 newThread.user_exception(excinfo, True)
374 finally: 400 finally:
375 sys.settrace(None) 401 sys.settrace(None)
376 402
377 class QThreadWrapper(module.QThread): 403 class QThreadWrapper(module.QThread):
378 """ Wrapper class for *.QThread. """ 404 """
379 405 Wrapper class for *.QThread.
406 """
380 def __init__(self, *args, **kwargs): 407 def __init__(self, *args, **kwargs):
408 """
409 Constructor
410 """
381 # Overwrite the provided run method with our own, to 411 # Overwrite the provided run method with our own, to
382 # intercept the thread creation by Qt 412 # intercept the thread creation by Qt
383 self.run = lambda s=self, run=self.run: ( 413 self.run = lambda s=self, run=self.run: (
384 _bootstrapQThread(s, run)) 414 _bootstrapQThread(s, run))
385 415

eric ide

mercurial