forked from M-Labs/artiq
1
0
Fork 0

worker: python docs recommend not replacing sys.modules

This commit is contained in:
Sebastien Bourdeauducq 2018-05-02 12:48:50 +08:00
parent 8c69d939fb
commit 8079aa6d20
1 changed files with 4 additions and 3 deletions

View File

@ -4,7 +4,6 @@ import os
import logging import logging
import traceback import traceback
from collections import OrderedDict from collections import OrderedDict
from copy import copy
import h5py import h5py
@ -153,11 +152,13 @@ class ExamineDatasetMgr:
def examine(device_mgr, dataset_mgr, file): def examine(device_mgr, dataset_mgr, file):
previous_modules = copy(sys.modules) previous_keys = set(sys.modules.keys())
try: try:
module = file_import(file) module = file_import(file)
finally: 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(): for class_name, exp_class in module.__dict__.items():
if class_name[0] == "_": if class_name[0] == "_":
continue continue