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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With