Skip to content

Commit 5457874

Browse files
committed
get the running loop to compile async state
1 parent 651539f commit 5457874

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

reflex/compiler/utils.py

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

55
import asyncio
6-
import concurrent.futures
76
import traceback
87
from collections.abc import Mapping, Sequence
98
from datetime import datetime
@@ -23,8 +22,7 @@
2322
from reflex.istate.storage import Cookie, LocalStorage, SessionStorage
2423
from reflex.state import BaseState, _resolve_delta
2524
from reflex.style import Style
26-
from reflex.utils import console, format, imports, path_ops
27-
from reflex.utils.exec import is_in_app_harness
25+
from reflex.utils import format, imports, path_ops
2826
from reflex.utils.imports import ImportVar, ParsedImportDict
2927
from reflex.utils.prerequisites import get_web_dir
3028
from reflex.vars.base import Field, Var
@@ -197,20 +195,11 @@ def compile_state(state: type[BaseState]) -> dict:
197195
"""
198196
initial_state = state(_reflex_internal_init=True).dict(initial=True)
199197
try:
200-
_ = asyncio.get_running_loop()
198+
loop = asyncio.get_running_loop()
201199
except RuntimeError:
202200
pass
203201
else:
204-
if is_in_app_harness():
205-
# Playwright tests already have an event loop running, so we can't use asyncio.run.
206-
with concurrent.futures.ThreadPoolExecutor() as pool:
207-
resolved_initial_state = pool.submit(
208-
asyncio.run, _resolve_delta(initial_state)
209-
).result()
210-
console.warn(
211-
f"Had to get initial state in a thread 🤮 {resolved_initial_state}",
212-
)
213-
return _sorted_keys(resolved_initial_state)
202+
return _sorted_keys(loop.run_until_complete(_resolve_delta(initial_state)))
214203

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

0 commit comments

Comments
 (0)