'Python Memory Leak in XLCalculator
I'm having some issues with a memory leak in the open source Python module XlCalculator.
It's causing my software to crash after running for a few hours, but I can't seem to figure out why the leak is occurring.
I'm assuming it's an issue where many ast_nodes are being left alive, but I don't understand Python garbage collection well enough to know what I can do about it and why the memory isn't being cleared.
Example code is below, which goes with an Excel file named 'simplesample' that contains two key cells - one called InputValue and one called OutputValue, where the output includes a function that contains the input.
Can anyone suggest how I can dive in and figure out the issue?
import tracemalloc
from xlcalculator import ModelCompiler, Model, Evaluator
import xmltodict
import traceback
import time
import json
import sys
import gc
from pympler import muppy, summary
filename = 'simplesample.xlsx'
cachefile = "simplesample.json"
print("Compiling Model")
compiler = ModelCompiler()
new_model = compiler.read_and_parse_archive(filename,build_code=False)
new_model.persist_to_json_file(cachefile)
print("Model Creation Complete")
#Load the JSON Model
print("Loading Model...")
mod = Model()
mod.construct_from_json_file(cachefile,build_code=True)
print("Model Load Complete")
while True:
#Create an evaulator from the model
print("Running 10000 Updates")
sheet = Evaluator(mod)
tmr = 0
while tmr < 10000:
tmr = tmr + 1
vl = sheet.evaluate('OutputValue')
#Show current memory allocations...
all_objects = muppy.get_objects()
sum1 = summary.summarize(all_objects)
summary.print_(sum1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
