Browse Source

feature: Use multi-thread to compiler pages (#1199)

TaiJuWu 1 year ago
parent
commit
00fc2f24f3
1 changed files with 12 additions and 6 deletions
  1. 12 6
      pynecone/app.py

+ 12 - 6
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)