lightweight-charts-python
lightweight-charts-python copied to clipboard
[BUG] Memory Leak Warning
Question
I am importing a class Chart() whose object I am creating in my code Someone raised a github issue with similar issue, there @louisnw01 replied that You must encapsulate the Chart object within an if name == 'main' block.
Now I'll explain what my code is doing Inside the if name == 'main' block, I am invoking an async function using asyncio.run(main()) Now Inside the main, I am awaiting another async function called processMessage which is written in another file, and inside that processMessage Function I am invoking another function called createChart which is again in another file which is creating the Chart object and it returns the screenshot in bytes array.
I am not sure what I am doing wrong I even tried to delete the chart object which I created from Chart class This is where I am creating Chart object I am invoking this function through another function which is called insides if name=='main' block, I am not sure how to fix it
import pandas as pd
from dtos.webhookDtos import SmaCreateChart
import gc
def createChart(data: pd.DataFrame, sma: SmaCreateChart = None):
chart = Chart()
if sma:
line = chart.create_line(name=f'SMA {sma.period}')
line.set(sma.data)
chart.set(data)
chart.show(block=False)
img = chart.screenshot()
chart.exit()
del chart
gc.collect()
return img
### Code example
_No response_