ITADN

Problem in adding multiple Python modules to ModuleManager

#328Openkeceli 创建于 2023-12-20
K
kecelicommented
I have been observing intermittent errors with Python modules like `IndexError: map::at` with `mod.change_input()` when I have more than one Python module in the module manager. The problem never happens if I have only one Python module, but happens randomly if I have more than one. I think the code below shows the root of the problem. ```python import pluginplay as pp from py_test_pluginplay import OneInOneOut, OneIn, OneOut ptype = OneInOneOut() class test_module(pp.ModuleBase): """Basic PluginPlay module that satisfies OneInOneOut property type""" def __init__(self): pp.ModuleBase.__init__(self) self.description(self.__doc__) self.satisfies_property_type(ptype) def run_(self, inputs, submods): s, = ptype.unwrap_inputs(inputs) r = self.results() return ptype.wrap_results(r, s) ptype = OneIn() class test_module2(pp.ModuleBase): """Basic PluginPlay module that satisfies OneIn property type""" def __init__(self): pp.ModuleBase.__init__(self) self.description(self.__doc__) self.satisfies_property_type(ptype) def run_(self, inputs, submods): s, = ptype.unwrap_inputs(inputs) r = self.results() return ptype.wrap_results(r, s) ptype = OneOut() class test_module3(pp.ModuleBase): def __init__(self): pp.ModuleBase.__init__(self) self.satisfies_property_type(ptype) self.add_input('inp2') def run_(self, inputs, submods): r = self.results() return ptype.wrap_results(r) mm = pp.ModuleManager() mm.add_module('test_module', test_module()) mm.add_module('test_module2', test_module2()) mm.add_module('test_module3', test_module3()) for key in mm.keys(): print(key, mm[key]) print(mm['test_module'] == mm['test_module2']) print(mm.at('test_module') == mm.at('test_module2')) ``` If you run the Python code above several times, you will get something like: ```bash (nwx) 01:15:00|nwx|test> python mm_test3.py test_module <pluginplay.Module object at 0x7fafa0d2a330> test_module2 <pluginplay.Module object at 0x7fafa0d24a70> test_module3 <pluginplay.Module object at 0x7fafa0d1d970> True True (nwx) 01:15:02|nwx|test> python mm_test3.py test_module <pluginplay.Module object at 0x7f290c631530> test_module2 <pluginplay.Module object at 0x7f290c631530> test_module3 <pluginplay.Module object at 0x7f290c631530> True True ``` Somehow in the second run, `test_module`s that satisfy different property types are stored at the same memory location. Module comparison always returns True might be because the comparison operator not being exported, but I think main issue is that Python modules are not added to the module manager properly. Maybe this issue is related to #309 somehow.
3 条评论