import os import time import importlib def main(): for i in range(100): test(i) def test(i): module_name = 'import_testee_{}'.format(i) remove_if_exists(module_name + '.py') create_module(module_name + '.py') importlib.import_module(module_name) remove_if_exists(module_name + '.py') def remove_if_exists(path): if os.path.exists(path): os.unlink(path) def create_module(module_path): with open(module_path, 'w'): pass if __name__ == "__main__": main()