From 00fc2f24f32a7068b4fe3e3835fddbd6c08372e0 Mon Sep 17 00:00:00 2001 From: TaiJuWu <33004323+TaiJuWu@users.noreply.github.com> Date: Sat, 17 Jun 2023 04:41:42 +0800 Subject: [PATCH] feature: Use multi-thread to compiler pages (#1199) --- pynecone/app.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pynecone/app.py b/pynecone/app.py index c01ceefa1..922fa2480 100644 --- a/pynecone/app.py +++ b/pynecone/app.py @@ -2,6 +2,7 @@ import asyncio import inspect +from multiprocessing.pool import ThreadPool from typing import ( Any, AsyncIterator, @@ -454,17 +455,22 @@ class App(Base): # Compile the pages. custom_components = set() + thread_pool = ThreadPool() for route, component in self.pages.items(): component.add_style(self.style) - compiler.compile_page( - route, - component, - self.state, - self.connect_error_component, + thread_pool.apply_async( + compiler.compile_page, + args=( + route, + component, + self.state, + self.connect_error_component, + ), ) - # Add the custom components from the page to the set. custom_components |= component.get_custom_components() + thread_pool.close() + thread_pool.join() # Compile the custom components. compiler.compile_components(custom_components)