Make threading.Timer() usable while debugging (fixes issue #262).

Wed, 21 Mar 2018 22:13:31 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Wed, 21 Mar 2018 22:13:31 +0100
changeset 6195
186cbd6b15b1
parent 6194
05df94843dd5
child 6196
7135a692e43e

Make threading.Timer() usable while debugging (fixes issue #262).

DebugClients/Python/ThreadExtension.py file | annotate | diff | comparison | revisions
--- a/DebugClients/Python/ThreadExtension.py	Tue Mar 13 19:48:43 2018 +0100
+++ b/DebugClients/Python/ThreadExtension.py	Wed Mar 21 22:13:31 2018 +0100
@@ -324,6 +324,7 @@
                 """ Wrapper class for threading.Thread. """
                 
                 def __init__(self, *args, **kwargs):
+                    """ Constructor. """
                     # Overwrite the provided run method with our own, to
                     # intercept the thread creation by threading.Thread
                     self.run = lambda s=self, run=self.run: _bootstrap(s, run)
@@ -331,6 +332,25 @@
                     super(ThreadWrapper, self).__init__(*args, **kwargs)
             
             module.Thread = ThreadWrapper
+            
+            # Special handling of threading.(_)Timer
+            if sys.version_info[0] == 2:
+                timer = module._Timer
+            else:
+                timer = module.Timer
+                
+            class TimerWrapper(timer, ThreadWrapper):
+                """ Wrapper class for threading.(_)Timer. """
+                
+                def __init__(self, interval, function, *args, **kwargs):
+                    """ Constructor. """
+                    super(TimerWrapper, self).__init__(
+                        interval, function, *args, **kwargs)
+            
+            if sys.version_info[0] == 2:
+                module._Timer = TimerWrapper
+            else:
+                module.Timer = TimerWrapper
         
         # Add hook for *.QThread
         elif (fullname in ['PyQt4.QtCore', 'PyQt5.QtCore',

eric ide

mercurial