From 1e55a45a1e8c9252fc9c42979f80b256db4fb5ca Mon Sep 17 00:00:00 2001 From: Jackie Tung Date: Mon, 23 Oct 2023 10:22:35 -0700 Subject: [PATCH] [reflex hosting] clean up tmp dir for storing zip archives --- reflex/reflex.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/reflex/reflex.py b/reflex/reflex.py index 6f3cf16bca..4180841534 100644 --- a/reflex/reflex.py +++ b/reflex/reflex.py @@ -5,6 +5,7 @@ import contextlib import json import os +import shutil import tempfile import time from datetime import datetime @@ -560,8 +561,8 @@ def deploy( # Compile the app in production mode. config.api_url = api_url config.deploy_url = deploy_url + tmp_dir = tempfile.mkdtemp() try: - tmp_dir = tempfile.mkdtemp() export( frontend=True, backend=True, @@ -574,6 +575,9 @@ def deploy( f"Encountered ImportError, did you install all the dependencies? {ie}" ) raise typer.Exit(1) from ie + finally: + if os.path.exists(tmp_dir): + shutil.rmtree(tmp_dir) frontend_file_name = constants.ComponentName.FRONTEND.zip() backend_file_name = constants.ComponentName.BACKEND.zip() @@ -601,6 +605,9 @@ def deploy( except Exception as ex: console.error(f"Unable to deploy due to: {ex}") raise typer.Exit(1) from ex + finally: + if os.path.exists(tmp_dir): + shutil.rmtree(tmp_dir) # Deployment will actually start when data plane reconciles this request console.debug(f"deploy_response: {deploy_response}")