From 4411482b9bdc94a6a33494dce67620b77f9a0a30 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 3 May 2022 14:22:40 +0300 Subject: [PATCH] Fix bugs --- app/main.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/main.py b/app/main.py index ebe7343..cc2a590 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,6 @@ import asyncio -from concurrent.futures import ThreadPoolExecutor import os +import os.path import time from typing import AsyncIterator import uuid @@ -96,16 +96,12 @@ app.include_router(router) @app.on_event("startup") @repeat_every(seconds=60, raise_exceptions=True) -async def remove_temp_files(): - def _foo(): - current_time = time.time() +def remove_temp_files(): + current_time = time.time() - for f in os.listdir("/tmp/"): - creation_time = os.path.getctime(f) - if (current_time - creation_time) // 3600 >= 3: - os.unlink(f) + for f in os.listdir("/tmp/"): + target_path = f"/tmp/{f}" - loop = asyncio.get_event_loop() - - with ThreadPoolExecutor(1) as executor: - await loop.run_in_executor(executor, _foo) + creation_time = os.path.getctime(target_path) + if (current_time - creation_time) // 3600 >= 3: + os.unlink(target_path)