eric6/DebugClients/Python/ThreadExtension.py

branch
maintenance
changeset 7642
72721823d453
parent 7437
1148ca40ea36
parent 7639
422fd05e9c91
child 7924
8a96736d465e
--- a/eric6/DebugClients/Python/ThreadExtension.py	Sun May 31 17:26:46 2020 +0200
+++ b/eric6/DebugClients/Python/ThreadExtension.py	Sat Jul 04 11:45:34 2020 +0200
@@ -11,11 +11,7 @@
 import sys
 import importlib
 
-if sys.version_info[0] == 2:
-    import thread as _thread
-else:
-    import _thread
-
+import _thread
 import threading
 
 from DebugBase import DebugBase
@@ -54,13 +50,8 @@
         # special objects representing the main scripts thread and frame
         self.mainThread = self
         
-        if sys.version_info[0] == 2:
-            self.threadModName = 'thread'
-        else:
-            self.threadModName = '_thread'
-        
         # reset already imported thread module to apply hooks at next import
-        del sys.modules[self.threadModName]
+        del sys.modules['_thread']
         del sys.modules['threading']
         
         sys.meta_path.insert(0, self)
@@ -260,9 +251,9 @@
         if fullname in sys.modules or not self.debugging:
             return None
         
-        if fullname in [self.threadModName, 'PyQt4.QtCore', 'PyQt5.QtCore',
-                        'PySide.QtCore', 'PySide2.QtCore', 'greenlet',
-                        'threading'] and self.enableImportHooks:
+        if fullname in ['_thread', 'PyQt5.QtCore', 'PySide2.QtCore',
+                        'greenlet', 'threading'
+                        ] and self.enableImportHooks:
             # Disable hook to be able to import original module
             self.enableImportHooks = False
             return self
@@ -280,7 +271,7 @@
         """
         module = importlib.import_module(fullname)
         sys.modules[fullname] = module
-        if (fullname == self.threadModName and
+        if (fullname == '_thread' and
                 self._original_start_new_thread is None):
             # make thread hooks available to system
             self._original_start_new_thread = module.start_new_thread
@@ -337,10 +328,7 @@
             module.Thread = ThreadWrapper
             
             # Special handling of threading.(_)Timer
-            if sys.version_info[0] == 2:
-                timer = module._Timer
-            else:
-                timer = module.Timer
+            timer = module.Timer
                 
             class TimerWrapper(timer, ThreadWrapper):
                 """
@@ -353,10 +341,7 @@
                     super(TimerWrapper, self).__init__(
                         interval, function, *args, **kwargs)
             
-            if sys.version_info[0] == 2:
-                module._Timer = TimerWrapper
-            else:
-                module.Timer = TimerWrapper
+            module.Timer = TimerWrapper
         
             # Special handling of threading._DummyThread
             class DummyThreadWrapper(module._DummyThread, ThreadWrapper):
@@ -372,9 +357,8 @@
             module._DummyThread = DummyThreadWrapper
         
         # Add hook for *.QThread
-        elif (fullname in ['PyQt4.QtCore', 'PyQt5.QtCore',
-                           'PySide.QtCore', 'PySide2.QtCore'] and
-                self.qtThreadAttached is False):
+        elif (fullname in ['PyQt5.QtCore', 'PySide2.QtCore'] and
+              self.qtThreadAttached is False):
             self.qtThreadAttached = True
             # _debugClient as a class attribute can't be accessed in following
             # class. Therefore we need a global variable.
@@ -448,6 +432,3 @@
         
         self.enableImportHooks = True
         return module
-
-#
-# eflag: noqa = M702

eric ide

mercurial