Skip to content

Commit

Permalink
feat: deprecate use_thread
Browse files Browse the repository at this point in the history
  • Loading branch information
iisakkirotko committed Dec 23, 2024
1 parent 6328ea7 commit 5e49cc6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion solara/hooks/use_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

import solara
from solara.datatypes import Result, ResultState
from solara.util import cancel_guard, nullcontext
from solara.util import cancel_guard, nullcontext, deprecated

SOLARA_ALLOW_OTHER_TRACER = os.environ.get("SOLARA_ALLOW_OTHER_TRACER", False) in (True, "True", "true", "1")
T = TypeVar("T")
logger = logging.getLogger("solara.hooks.use_thread")


@deprecated("use_thread is deprecated, use use_task or Task instead")
def use_thread(
callback: Union[
Callable[[threading.Event], T],
Expand Down
23 changes: 23 additions & 0 deletions solara/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
from urllib.parse import urlencode
import warnings

if TYPE_CHECKING:
import numpy as np
Expand Down Expand Up @@ -346,3 +347,25 @@ def wrapper():
return return_value

return wrapper


def deprecated(reason: str):
"""
Mark functions as deprecated.
"""

def decorator(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
reason,
category=DeprecationWarning,
stacklevel=2, # this way we show the line where the function is called
)
warnings.simplefilter("default", DeprecationWarning)
return func(*args, **kwargs)

return wrapped

return decorator
4 changes: 3 additions & 1 deletion solara/website/pages/documentation/api/hooks/use_thread.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# use_thread
# use_thread (deprecated)

### use_thread is deprecated, use [use_task](/documentation/components/lab/use_task) or [Task](/documentation/components/lab/task) instead

```python
def use_thread(
Expand Down
2 changes: 1 addition & 1 deletion solara/website/pages/documentation/api/hooks/use_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from solara.alias import rw

HERE = Path(__file__).parent
title = "use_thread"
title = "use_thread (deprecated)"
__doc__ = open(HERE / "use_thread.md").read()


Expand Down

0 comments on commit 5e49cc6

Please sign in to comment.