Skip to content

Commit 413d72d

Browse files
committed
ok i hate this
1 parent 22ad425 commit 413d72d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

reflex/compiler/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import concurrent.futures
67
import traceback
78
from collections.abc import Mapping, Sequence
89
from datetime import datetime
@@ -195,12 +196,15 @@ def compile_state(state: type[BaseState]) -> dict:
195196
"""
196197
initial_state = state(_reflex_internal_init=True).dict(initial=True)
197198
try:
198-
loop = asyncio.get_running_loop()
199+
_ = asyncio.get_running_loop()
199200
except RuntimeError:
200201
pass
201202
else:
202-
future = asyncio.run_coroutine_threadsafe(_resolve_delta(initial_state), loop)
203-
return _sorted_keys(future.result())
203+
with concurrent.futures.ThreadPoolExecutor() as pool:
204+
resolved_initial_state = pool.submit(
205+
asyncio.run, _resolve_delta(initial_state)
206+
).result()
207+
return _sorted_keys(resolved_initial_state)
204208

205209
# Normally the compile runs before any event loop starts, we asyncio.run is available for calling.
206210
return _sorted_keys(asyncio.run(_resolve_delta(initial_state)))

0 commit comments

Comments
 (0)