Reading multiple components does not work
zegervdv opened this issue · comments
When reading in 2 components in the same python instance, the second one is incomplete:
In [1]: f1 = open('file1.xml', 'r')
In [2]: f2 = open('file2.xml', 'r')
In [3]: from ipyxact.ipyxact import Component
In [4]: c1 = Component()
In [5]: c2 = Component()
In [6]: c1.load(f1)
In [7]: c2.load(f2)
In [8]: c1.memoryMaps
Out[8]: <ipyxact.ipyxact.MemoryMaps at 0x2ffa290>
In [9]: c1.memoryMaps.memoryMap
Out[9]:
[<ipyxact.ipyxact.MemoryMap at 0x3085dd0>,
<ipyxact.ipyxact.MemoryMap at 0x30870d0>]
In [10]: c2.memoryMaps
In [11]: c2.memoryMaps.memoryMap
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-11-4b0e797fcc70> in <module>()
----> 1 c2.memoryMaps.memoryMap
AttributeError: 'NoneType' object has no attribute 'memoryMap'
I need to start a new python interpreter and load everything again to be able to read the second file correctly.
I tried by deleting the references to c1
and by unloading/reloading the module but only a fresh python interpreter will make it work again.
Changing the order of the opening, instance creation or loading does not make a difference.
Ouch. That doesn't sound nice. I'm probably doing some questionable things here. Don't have a good idea for now, but the long-term solution will be to move to another API that is created by generateDS. There's some preliminary work here
For now I'm working around it by using a ProcessPoolExecutor
and running each import in a separate process.
From version 0.3.0 and onwards, a new API will be used which hopefully doesn't have this problem. You can find the new API here and I will push some example code later on