class XmlHandler(ContentHandler):
def startElement(self, name, attrs):
if name == 'Objects':
print('start')
elif name == 'Object':
self.obj = attrs['param]'
def endElement(self, name):
if name == 'Objects':
print('end')
elif name == 'Object':
self.obj.save()
xml.sax.parse(xml_path, XmlHandler())
class Obj(Model):
id = Column(UUID, primary_key=True)
class XmlHandler(ContentHandler):
def __init__(self):
pass
def startElement(self, name, attrs):
if name == 'Objects':
print('start parse')
elif name == 'Object':
aoid = attrs['ID']
self.obj = Obj.query.filter_by(id=id).first() # это 2-ое узкое место
if not self.obj:
self.obj = Obj()
def endElement(self, name):
if name == 'Objects':
print('end')
elif name == 'Object':
self.obj.save()
gc.collect() # это было 1-ое узкое место
xml.sax.parse(xml_path, XmlHandler())