diff --git a/artiq/tools.py b/artiq/tools.py index d7c3aab91..b3af4ef0b 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -7,6 +7,7 @@ import os import atexit import string import random +from copy import copy import numpy as np @@ -85,8 +86,12 @@ def file_import(filename, prefix="file_import_"): path = os.path.dirname(os.path.realpath(filename)) sys.path.insert(0, path) try: - loader = importlib.machinery.SourceFileLoader(modname, filename) - module = loader.load_module() + previous_modules = copy(sys.modules) + try: + loader = importlib.machinery.SourceFileLoader(modname, filename) + module = loader.load_module() + finally: + sys.modules = previous_modules finally: sys.path.remove(path)