From 8079aa6d208c5115823c9c95cebaa1e05b71bede Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 2 May 2018 12:48:50 +0800 Subject: [PATCH] worker: python docs recommend not replacing sys.modules --- artiq/master/worker_impl.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/artiq/master/worker_impl.py b/artiq/master/worker_impl.py index 4aec04afb..836ff6050 100644 --- a/artiq/master/worker_impl.py +++ b/artiq/master/worker_impl.py @@ -4,7 +4,6 @@ import os import logging import traceback from collections import OrderedDict -from copy import copy import h5py @@ -153,11 +152,13 @@ class ExamineDatasetMgr: def examine(device_mgr, dataset_mgr, file): - previous_modules = copy(sys.modules) + previous_keys = set(sys.modules.keys()) try: module = file_import(file) finally: - sys.modules = previous_modules + new_keys = set(sys.modules.keys()) + for key in new_keys - previous_keys: + del sys.modules[key] for class_name, exp_class in module.__dict__.items(): if class_name[0] == "_": continue