From 5d406b666ba3e13b10c25b26c538d52d11784286 Mon Sep 17 00:00:00 2001 From: Kaveen Kumarasinghe Date: Tue, 31 Jan 2023 22:40:03 -0500 Subject: [PATCH] remove .cleanup() for temp_path (it gets auto cleaned up its ok --- models/index_model.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/models/index_model.py b/models/index_model.py index dff686b..0ac6682 100644 --- a/models/index_model.py +++ b/models/index_model.py @@ -58,17 +58,15 @@ class Index_handler: await ctx.respond("Only accepts txt or pdf files") return async with aiofiles.tempfile.TemporaryDirectory() as temp_path: - async with aiofiles.tempfile.NamedTemporaryFile(suffix=suffix, dir=temp_path.name, delete=False) as temp_file: + async with aiofiles.tempfile.NamedTemporaryFile(suffix=suffix, dir=temp_path, delete=False) as temp_file: await file.save(temp_file.name) - index = await self.loop.run_in_executor(None, partial(self.index_file, temp_path.name)) + index = await self.loop.run_in_executor(None, partial(self.index_file, temp_path)) self.index_storage[ctx.user.id] = index - temp_path.cleanup() await ctx.respond("Index set") except Exception: await ctx.respond("Failed to set index") traceback.print_exc() - async def set_discord_index(self, ctx: discord.ApplicationContext, channel: discord.TextChannel, user_api_key): if not user_api_key: os.environ["OPENAI_API_KEY"] = self.openai_key