322 |
322 |
323 class ThreadWrapper(module.Thread): |
323 class ThreadWrapper(module.Thread): |
324 """ Wrapper class for threading.Thread. """ |
324 """ Wrapper class for threading.Thread. """ |
325 |
325 |
326 def __init__(self, *args, **kwargs): |
326 def __init__(self, *args, **kwargs): |
|
327 """ Constructor. """ |
327 # Overwrite the provided run method with our own, to |
328 # Overwrite the provided run method with our own, to |
328 # intercept the thread creation by threading.Thread |
329 # intercept the thread creation by threading.Thread |
329 self.run = lambda s=self, run=self.run: _bootstrap(s, run) |
330 self.run = lambda s=self, run=self.run: _bootstrap(s, run) |
330 |
331 |
331 super(ThreadWrapper, self).__init__(*args, **kwargs) |
332 super(ThreadWrapper, self).__init__(*args, **kwargs) |
332 |
333 |
333 module.Thread = ThreadWrapper |
334 module.Thread = ThreadWrapper |
|
335 |
|
336 # Special handling of threading.(_)Timer |
|
337 if sys.version_info[0] == 2: |
|
338 timer = module._Timer |
|
339 else: |
|
340 timer = module.Timer |
|
341 |
|
342 class TimerWrapper(timer, ThreadWrapper): |
|
343 """ Wrapper class for threading.(_)Timer. """ |
|
344 |
|
345 def __init__(self, interval, function, *args, **kwargs): |
|
346 """ Constructor. """ |
|
347 super(TimerWrapper, self).__init__( |
|
348 interval, function, *args, **kwargs) |
|
349 |
|
350 if sys.version_info[0] == 2: |
|
351 module._Timer = TimerWrapper |
|
352 else: |
|
353 module.Timer = TimerWrapper |
334 |
354 |
335 # Add hook for *.QThread |
355 # Add hook for *.QThread |
336 elif (fullname in ['PyQt4.QtCore', 'PyQt5.QtCore', |
356 elif (fullname in ['PyQt4.QtCore', 'PyQt5.QtCore', |
337 'PySide.QtCore', 'PySide2.QtCore'] and |
357 'PySide.QtCore', 'PySide2.QtCore'] and |
338 self.qtThreadAttached is False): |
358 self.qtThreadAttached is False): |