KeepLastStream instance has no attribute 'close'

1 post / 0 new
Joined: 2017-10-19
KeepLastStream instance has no attribute 'close'

Version of - 2.0

Operating system:  Ubuntu 17.04, 64bit


Exception in thread Thread-1:
Traceback (most recent call last):
  File "/opt/CBMX/lib/python2.7/", line 801, in __bootstrap_inner
  File "/home/mazhenir/.cbmx/libraries/jmodelica/JModelica/Python/pymodelica/", line 222, in run
    xml.sax.parse(, LogErrorParser(self.result))
  File "/opt/CBMX/lib/python2.7/xml/sax/", line 33, in parse
  File "/opt/CBMX/lib/python2.7/xml/sax/", line 116, in parse
  File "/opt/CBMX/lib/python2.7/xml/sax/", line 235, in _close_source
AttributeError: KeepLastStream instance has no attribute 'close'


The root cause:

File (the latest version) has method "_close_source()" to close source stream, but KeepLastStream doesn't have it.

 The quick fix - just to add method close() to  KeepLastStream .


class KeepLastStream():
    Internal class that records the last contents sent to the SAX parser.
    It is necessary so that we can recover from SAX parser errors that is
    thrown when the compiler fail to start properly. For example when the
    JVM is unable to allocate enough memory.
def __init__(self, stream): = stream
        self.last = None
        self.secondLastLine = None
        self.lastLine = ''
self.line = 1 # Number of lines that has been read read
self.errorMessage = None

    def close(self):



Example to reproduce:


file ""

model FirstOrder
  Real x;
  der(x) = 1-x;
end FirstOrder;



from jmodelica import pyfmi, pymodelica
from pymodelica import compile_fmu
from pyfmi import load_fmu

mo_file = ""
class_name = 'FirstOrder'
my_fmu = compile_fmu(class_name, mo_file)

first_order = load_fmu(my_fmu)
res = first_order.simulate(final_time=30)