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 12, 2024
1 parent 17a7148 commit 3cdce2b
Show file tree
Hide file tree
Showing 11 changed files with 1,216 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codequality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install ".[dev]" mypy==0.991 black==22.12.0 codespell==2.2.4 "click<8.1.4" "traitlets<5.10.0" "matplotlib<3.8.0"
pip install ".[dev]" mypy==1.1.1 black==22.12.0 codespell==2.2.4 "click<8.1.4" "traitlets<5.10.0" "matplotlib<3.8.0"
mypy --install-types --non-interactive solara
- name: Run codespell
run: codespell
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
files: \.py$
args: [--profile=black]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.991" # Use the sha / tag you want to point at
rev: "v1.1.1" # Use the sha / tag you want to point at
hooks:
- id: mypy
args: [--no-strict-optional, --ignore-missing-imports]
Expand Down
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 # 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 3cdce2b

Please sign in to comment.