Skip to content

Commit

Permalink
feat: task and use_task for better asyncio task a thread execution
Browse files Browse the repository at this point in the history
use_task can replace use_thread, but also support coroutine functions.

task is a decorator that creates a top level task that can be executed
from any location (e.g. a click handler of a button).
  • Loading branch information
maartenbreddels committed Feb 14, 2024
1 parent 1980856 commit d39063b
Show file tree
Hide file tree
Showing 7 changed files with 1,352 additions and 3 deletions.
1 change: 1 addition & 0 deletions solara/lab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# isort: skip_file
from .components import * # noqa: F401, F403
from ..server.kernel_context import on_kernel_start # noqa: F401
from ..tasks import task, use_task, Task, TaskResult # noqa: F401, F403
from ..toestand import computed # noqa: F401


Expand Down
6 changes: 3 additions & 3 deletions solara/server/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ async def process_messages_task(self):
await self.ws.send_text(first)

def close(self):
self.portal.call(self.ws.close)
self.portal.call(self.ws.close) # type: ignore

def send_text(self, data: str) -> None:
if settings.main.experimental_performance:
self.to_send.append(data)
else:
self.portal.call(self.ws.send_bytes, data)
self.portal.call(self.ws.send_bytes, data) # type: ignore

def send_bytes(self, data: bytes) -> None:
if settings.main.experimental_performance:
self.to_send.append(data)
else:
self.portal.call(self.ws.send_bytes, data)
self.portal.call(self.ws.send_bytes, data) # type: ignore

async def receive(self):
if hasattr(self.portal, "start_task_soon"):
Expand Down
Loading

0 comments on commit d39063b

Please sign in to comment.