add run_in_thread (#3077)

This commit is contained in:
Thomas Brandého 2024-04-12 01:42:14 +02:00 committed by GitHub
parent 4056ad613f
commit e377ce70b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

View File

@ -6,6 +6,7 @@ omit =
reflex/__main__.py
reflex/app_module_for_backend.py
reflex/components/chakra/*
reflex/experimental/*
[report]
show_missing = true

View File

@ -4,6 +4,7 @@ from types import SimpleNamespace
from ..utils.console import warn
from . import hooks as hooks
from .misc import run_in_thread as run_in_thread
warn(
"`rx._x` contains experimental features and might be removed at any time in the future .",
@ -11,4 +12,5 @@ warn(
_x = SimpleNamespace(
hooks=hooks,
run_in_thread=run_in_thread,
)

View File

@ -0,0 +1,12 @@
"""Miscellaneous functions for the experimental package."""
import asyncio
async def run_in_thread(func):
"""Run a function in a separate thread.
Args:
func (callable): The function to run.
"""
await asyncio.get_event_loop().run_in_executor(None, func)