eric7/DebugClients/Python/ModuleLoader.py

branch
eric7
changeset 8940
e91951ff3bbd
parent 8881
54e42bc2437a
equal deleted inserted replaced
8939:c88bb019e2b5 8940:e91951ff3bbd
26 @param debugClient reference to the debug client object 26 @param debugClient reference to the debug client object
27 @type DebugClient 27 @type DebugClient
28 """ 28 """
29 self.__dbgClient = debugClient 29 self.__dbgClient = debugClient
30 30
31 self.__enableImportHooks = True 31 self.__enableImportHooks = set()
32 32
33 # reset already imported thread module to apply hooks at next import 33 # reset already imported thread module to apply hooks at next import
34 for moduleName in ("thread", "_thread", "threading"): 34 for moduleName in ("thread", "_thread", "threading"):
35 if moduleName in sys.modules: 35 if moduleName in sys.modules:
36 del sys.modules[moduleName] 36 del sys.modules[moduleName]
57 @return reference to the loaded module 57 @return reference to the loaded module
58 @rtype module 58 @rtype module
59 """ 59 """
60 module = importlib.import_module(fullname) 60 module = importlib.import_module(fullname)
61 sys.modules[fullname] = module 61 sys.modules[fullname] = module
62 62 self.__enableImportHooks.remove(fullname)
63 ## Add hook for _thread.start_new_thread 63 ## Add hook for _thread.start_new_thread
64 if ( 64 if (
65 fullname == '_thread' and 65 fullname == '_thread' and
66 not hasattr(module, 'eric7_patched') 66 not hasattr(module, 'eric7_patched')
67 ): 67 ):
108 ): 108 ):
109 module.eric7_patched = True 109 module.eric7_patched = True
110 self.__dbgClient.patchQThread(module) 110 self.__dbgClient.patchQThread(module)
111 patchQProcess(module, self.__dbgClient) 111 patchQProcess(module, self.__dbgClient)
112 112
113 self.__enableImportHooks = True
114 return module 113 return module
115 114
116 def find_spec(self, fullname, path, target=None): 115 def find_spec(self, fullname, path, target=None):
117 """ 116 """
118 Public method returning the module spec. 117 Public method returning the module spec.
125 about what spec to return 124 about what spec to return
126 @type module 125 @type module
127 @return module spec object pointing to the module loader 126 @return module spec object pointing to the module loader
128 @rtype ModuleSpec 127 @rtype ModuleSpec
129 """ 128 """
130 if fullname in sys.modules or not self.__dbgClient.debugging: 129 if fullname in sys.modules or self.__dbgClient.debugging is False:
131 return None 130 return None
132 131
133 if ( 132 if (
134 fullname in self.__modulesToPatch and 133 fullname in self.__modulesToPatch and
135 self.__enableImportHooks 134 fullname not in self.__enableImportHooks
136 ): 135 ):
137 # Disable hook to be able to import original module 136 # Disable hook to be able to import original module
138 self.__enableImportHooks = False 137 self.__enableImportHooks.add(fullname)
139 return importlib.machinery.ModuleSpec(fullname, self) 138 return importlib.machinery.ModuleSpec(fullname, self)
140 139
141 return None 140 return None
142 141
143 def create_module(self, spec): 142 def create_module(self, spec):

eric ide

mercurial