Use ctime, not atime to find old files
This commit is contained in:
parent
21f897b5c3
commit
3ab9a2faa6
|
@ -82,7 +82,8 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
systemd.services.objectifier = {
|
||||
systemd.services = {
|
||||
objectifier = {
|
||||
after = [ "network-online.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
environment = {
|
||||
|
@ -133,4 +134,5 @@ in {
|
|||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ from detector import Detector
|
|||
from fastapi import FastAPI, HTTPException, Request, UploadFile, File
|
||||
from fastapi.responses import FileResponse
|
||||
from os import listdir, remove
|
||||
from os.path import getatime, splitext, basename, isfile
|
||||
from os.path import getctime, splitext, basename, isfile
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
|
@ -35,7 +35,7 @@ yolo_weights = get_envvar_or_fail('OBJECTIFIER_YOLOV3_WEIGHTS')
|
|||
yolo_labels_file = get_envvar_or_fail('OBJECTIFIER_YOLOV3_LABELS')
|
||||
buffer_size = to_int(get_envvar('OBJECTIFIER_BUFFER_SIZE')) or 524288
|
||||
max_file_age = to_int(get_envvar('OBJECTIFIER_CLEANUP_MAX_AGE'))
|
||||
file_cleanup_delay = to_int(get_envvar('OBJECTIFIER_CLEANUP_DELAY'))
|
||||
file_cleanup_delay = to_int(get_envvar('OBJECTIFIER_CLEANUP_DELAY')) or 60
|
||||
detection_timeout = to_int(get_envvar('OBJECTIFIER_TIMEOUT')) or 5
|
||||
pool_size = to_int(get_envvar('OBJECTIFIER_POOL_SIZE')) or 10
|
||||
|
||||
|
@ -61,12 +61,13 @@ img_formats = [ "png", "jpg", "gif", "bmp" ]
|
|||
|
||||
def cleanup_old_files(path, extensions, max_age):
|
||||
for filename in listdir(path):
|
||||
if (splitext(filename) in extensions) and (getatime(filename) - time.time() > max_age):
|
||||
if (splitext(filename) in extensions) and (getctime(filename) - time.time() > max_age):
|
||||
print("removing old output file: " + filename)
|
||||
remove(filename)
|
||||
|
||||
def run_cleanup_thread(path, extensions, age, delay):
|
||||
while True:
|
||||
print("running cleanup thread")
|
||||
cleanup_old_files(path, extensions, age)
|
||||
sleep(delay)
|
||||
|
||||
|
|
Loading…
Reference in New Issue