下面案例 仅是简单的举例;
实际的代码(for j in l ,这一段非常多),运行完一次后,电脑内存达到99.99%(电脑内存为48g)
需求为:运行完一次后,就释放内存,以便第二个时间点在运行;
import datetime
def fun(i10):
l = [1, 2, 3,4]
a=[1,2,3]
for j in l:
if j>a[i10]:
print(j
#每运行完一次,释放内存
d = []
times = ["22:22:00" , "22:22:05" , '22:22:10']
while True:
now = datetime.datetime.now()
time = datetime.datetime.strftime(now, '%H:%M:%S')
if time not in d and time in times:
d.append(time)
fun(times.index(time))
if len(d) == len(times):
break
import datetime
import time as t
def fun(i10):
l = [1, 2, 3, 4]
a = [1, 2, 3]
for j in l:
if j > a[i10]:
print(j,end=' ')
print()
# 每运行完一次,释放内存
d = []
times = ["13:09:00", "13:09:01", '13:09:02']
while True:
t.sleep(0.2)
now = datetime.datetime.now()
time = datetime.datetime.strftime(now, '%H:%M:%S')
if time not in d and time in times:
d.append(time)
fun(times.index(time))
if len(d) == len(times):
break
你这是定时任务吗,python有定时任务的模块