删除本地文件夹:
import os , string , datetime ;
str = '/home/aaa/tmp/tomcat/';
b = (datetime.datetime.now()).second + 5;
while 1 :
a = datetime.datetime.now();
if a.second == b :
files = os.listdir(str);
for file in files :
os.remove(str+file);
b = (a + datetime.timedelta(seconds=5)).second;
删除mongodb数据库:
import os , string , datetime , pymongo; conn = pymongo.Connection("127.0.0.1",27017);
db = conn.nn;
coll = db.nn_res;
b = (datetime.datetime.now()).second + 5;
while 1:
a = datetime.datetime.now();
if a.second == b :
curr = coll.find().sort("update_time",1).limit(1);
for tmp in curr :
coll.remove(tmp);
b = (a + datetime.timedelta(seconds=5)).second;