From 5600bc5a3057b1ef2c14d7abf3822976c5dd1573 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Mon, 11 Mar 2024 16:19:46 -0700 Subject: [PATCH] app: recognize REFLEX_COMPILE_PROCESSES and REFLEX_COMPILE_THREADS Control whether multiprocessing is used and the number of processes or threads that should be used. This will allow users to opt-in to the new, potentially hazardous, multiprocessing mode, which results in much faster compiles, but has already been reverted 4 times. Lets leave the code in this time, but use the thread pool executor by default. Limiting the number of threads or processes to 1 can also aid in debugging issues that arise during compile time. --- reflex/app.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/reflex/app.py b/reflex/app.py index c123d557a..d7c0786f8 100644 --- a/reflex/app.py +++ b/reflex/app.py @@ -860,12 +860,17 @@ class App(Base): # Use a forking process pool, if possible. Much faster, especially for large sites. # Fallback to ThreadPoolExecutor as something that will always work. executor = None - if platform.system() in ("Linux", "Darwin"): + if platform.system() in ("Linux", "Darwin") and os.environ.get( + "REFLEX_COMPILE_PROCESSES" + ): executor = concurrent.futures.ProcessPoolExecutor( - mp_context=multiprocessing.get_context("fork") + max_workers=int(os.environ.get("REFLEX_COMPILE_PROCESSES", 0)) or None, + mp_context=multiprocessing.get_context("fork"), ) else: - executor = concurrent.futures.ThreadPoolExecutor() + executor = concurrent.futures.ThreadPoolExecutor( + max_workers=int(os.environ.get("REFLEX_COMPILE_THREADS", 0)) or None, + ) with executor: result_futures = []