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

This commit is contained in:
TaiJuWu 2023-06-17 04:41:42 +08:00 committed by GitHub
parent 8947c26c7e
commit 00fc2f24f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)