mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Issue #17314: Stop using imp in multiprocessing.forking and move over
to importlib.
This commit is contained in:
		
							parent
							
								
									22c039bf50
								
							
						
					
					
						commit
						a33e11e436
					
				
					 2 changed files with 14 additions and 10 deletions
				
			
		| 
						 | 
					@ -450,6 +450,7 @@ def prepare(data):
 | 
				
			||||||
            # Main modules not actually called __main__.py may
 | 
					            # Main modules not actually called __main__.py may
 | 
				
			||||||
            # contain additional code that should still be executed
 | 
					            # contain additional code that should still be executed
 | 
				
			||||||
            import imp
 | 
					            import imp
 | 
				
			||||||
 | 
					            import importlib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if main_path is None:
 | 
					            if main_path is None:
 | 
				
			||||||
                dirs = None
 | 
					                dirs = None
 | 
				
			||||||
| 
						 | 
					@ -460,16 +461,17 @@ def prepare(data):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            assert main_name not in sys.modules, main_name
 | 
					            assert main_name not in sys.modules, main_name
 | 
				
			||||||
            sys.modules.pop('__mp_main__', None)
 | 
					            sys.modules.pop('__mp_main__', None)
 | 
				
			||||||
            file, path_name, etc = imp.find_module(main_name, dirs)
 | 
					            # We should not try to load __main__
 | 
				
			||||||
            try:
 | 
					 | 
				
			||||||
                # We should not do 'imp.load_module("__main__", ...)'
 | 
					 | 
				
			||||||
            # since that would execute 'if __name__ == "__main__"'
 | 
					            # since that would execute 'if __name__ == "__main__"'
 | 
				
			||||||
            # clauses, potentially causing a psuedo fork bomb.
 | 
					            # clauses, potentially causing a psuedo fork bomb.
 | 
				
			||||||
                main_module = imp.load_module(
 | 
					            loader = importlib.find_loader(main_name, path=dirs)
 | 
				
			||||||
                    '__mp_main__', file, path_name, etc
 | 
					            main_module = imp.new_module(main_name)
 | 
				
			||||||
                    )
 | 
					            try:
 | 
				
			||||||
            finally:
 | 
					                loader.init_module_attrs(main_module)
 | 
				
			||||||
                if file:
 | 
					            except AttributeError:  # init_module_attrs is optional
 | 
				
			||||||
                    file.close()
 | 
					                pass
 | 
				
			||||||
 | 
					            main_module.__name__ = '__mp_main__'
 | 
				
			||||||
 | 
					            code = loader.get_code(main_name)
 | 
				
			||||||
 | 
					            exec(code, main_module.__dict__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module
 | 
					            sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -112,6 +112,8 @@ Core and Builtins
 | 
				
			||||||
Library
 | 
					Library
 | 
				
			||||||
-------
 | 
					-------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #17314: Move multiprocessing.forking over to importlib.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue #11959: SMTPServer and SMTPChannel now take an optional map, use of
 | 
					- Issue #11959: SMTPServer and SMTPChannel now take an optional map, use of
 | 
				
			||||||
  which avoids affecting global state.
 | 
					  which avoids affecting global state.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue