diff -r 292cd0f213ff Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py Tue Feb 26 13:11:11 2013 +0000 +++ b/Lib/multiprocessing/forking.py Wed Feb 27 23:07:37 2013 +0000 @@ -438,7 +438,7 @@ elif main_name != 'ipython': # Main modules not actually called __main__.py may # contain additional code that should still be executed - import imp + import importlib if main_path is None: dirs = None @@ -449,16 +449,10 @@ assert main_name not in sys.modules, main_name sys.modules.pop('__mp_main__', None) - file, path_name, etc = imp.find_module(main_name, dirs) - try: - # We should not do 'imp.load_module("__main__", ...)' - # since that would execute 'if __name__ == "__main__"' - # clauses, potentially causing a psuedo fork bomb. - main_module = imp.load_module( - '__mp_main__', file, path_name, etc - ) - finally: - if file: - file.close() - - sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module + loader = importlib.find_loader(main_name, dirs) + # We should not import the module with __name__ == '__main__' + # since that would execute 'if __name__ == "__main__"' + # clauses, potentially causing a psuedo fork bomb. + loader.name = '__mp_main__' + loader.load_module() + sys.modules['__main__'] = sys.modules['__mp_main__']