1515# but WITHOUT ANY WARRANTY; without even the implied warranty of
1616# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1717# GNU General Public License for more details.
18- #
18+
1919# You should have received a copy of the GNU General Public License
2020# along with this program. If not, see <http://www.gnu.org/licenses/>
2121
2222import MLC .Log .log as lg
2323import importlib
24+ import imp
25+ import os
2426import sys
2527
2628from MLC .mlc_parameters .mlc_parameters import Config
@@ -34,25 +36,26 @@ def get_callback():
3436 function_name = Config .get_instance ().get ('EVALUATOR' , 'evaluation_function' )
3537 module_name = 'Evaluation.{0}' .format (function_name )
3638
37- # try:
38- # # WARNING: I am unloading manually the evaluation function module. I need to do this
39- # # because Python does not support module unloading and my evaluation functions are
40- # # all the same, so when one experiment loads his module, other project with the same
41- # # name of module won't be able to load yours
42- # # ev_module = sys.modules["Evaluation"]
43- # # del sys.modules['Evaluation']
44- # # del ev_module
45- # lg.logger_.debug("[EV_FACTORY] Module {0} was removed".format(sys.modules["Evaluation"]))
46- # except KeyError as err:
47- # # If the module cannot be unload because it does not exists, continue
48- # pass
39+ try :
40+ # WARNING: I am unloading manually the evaluation function module. I need to do this
41+ # because Python does not support module unloading and my evaluation functions are
42+ # all the same, so when one experiment loads his module, other project with the same
43+ # name of module won't be able to load yours
44+ ev_module = sys .modules ["Evaluation" ]
45+ print (ev_module )
46+ del sys .modules ['Evaluation' ]
47+ del ev_module
48+ lg .logger_ .debug ("[EV_FACTORY] Module {0} was removed" .format (sys .modules ["Evaluation" ]))
49+ except KeyError as err :
50+ # If the module cannot be unload because it does not exists, continue
51+ pass
4952
5053 lg .logger_ .debug ('[EV_FACTORY] Importing module {0}' .format (module_name ))
5154 try :
52- # lg.logger_.debug("[EV_FACTORY] Sys.path: {0}".format(sys.path))
53- module = importlib . import_module ( module_name )
54- importlib . reload ( module )
55- return module
55+ return imp . load_source ( "Evaluation." + function_name ,
56+ os . path . join ( * [ sys . path [ - 1 ],
57+ "Evaluation" ,
58+ function_name + ".py" ]))
5659 except ImportError as err :
5760 lg .logger_ .debug ("[EV_FACTORY] Evaluation function doesn't exists. "
5861 "Aborting program. Error Msg: {0}" .format (err ))
0 commit comments