9/10/2013

python datetime timedelta



import datetime

tmp1 = date1 + date2
tmp2_bool = date1 > date2 # return True
today = datetime.date.today()
five_days_after = today + datetime.timedelta(days=5)
seven_days_before = today - datetime.timedelta(days=7)
seven_days_five_hours_before = today - datetime.timedelta(days=7, hours=5)
date1 = datetime.timedelta(hours=5) # 5 hours later from now
date2 = datetime.timedelta(days=-5) # 5 days earlyer from today


.

9/09/2013

correction of mem leak of django + apache


The code below consume large memory and don't return.
Apache process memory will keep increasing with the code below.


aaa = data.objects.all().order_by('-id')
count_of_aaa = len(aaa)

The problem is "len(aaa)". (dunno why)
It should be replace by ...

count_of_aaa = aaa.count()

Then no mem leak occur.