Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this python script slowly chewing up my RAM?

This script slowly eats my RAM. When I run it, I can see the RAM usage of Python creep up by approx 1mb with each loop, but I can't figure out why. I have figured out that it is the iteration of the query that adds the RAM, but that's all I can figure out. Any help would be awesome.

from haystack.pmod import piliPlacement #this is the SA model
from time import sleep
from datetime import datetime
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker


now = datetime.now()


engine = create_engine('mssql://xxxxxxx;uid=user;pwd=xxxxx',echo=False)


Session = sessionmaker(bind=engine)


def syncPlacements(session):
    query = session.query(piliPlacement).filter(piliPlacement.Time > now)
    pili_placements = [p.ID_Placement for p in query.all()] # this is what adds the RAM
    del pili_placements
    print 'loop'


while True:
    session = Session()
    syncPlacements(session)
    sleep(3)
like image 547
MFB Avatar asked Dec 28 '25 14:12

MFB


1 Answers

After stripping it right back, and chatting to a guy on the SA IRC channel, it appeared to be a Mac OSX only problem. So I set it up on Linux but the same thing occured. In the end, I resorted to running the script on a crontab. Works fine now.

M

like image 126
MFB Avatar answered Dec 30 '25 06:12

MFB