Skip to content

Commit eb82056

Browse files
committed
deprecate @ez.thread decorator
1 parent 67fac39 commit eb82056

5 files changed

Lines changed: 85 additions & 0 deletions

File tree

ISSUE_deprecate_ez_thread.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Deprecate `@ez.thread` Decorator
2+
3+
## Summary
4+
Deprecate `@ez.thread` in `ezmsg.core` and guide users to explicit background execution patterns (`loop.run_in_executor(...)` / explicit task lifecycle management).
5+
6+
## Motivation
7+
- `@ez.thread` has no cooperative termination contract and does not integrate cleanly with unit lifecycle shutdown.
8+
- Equivalent behavior is already available with explicit executor usage.
9+
- Keeping `@ez.thread` adds an extra concurrency model surface area without strong adoption.
10+
11+
## Proposal
12+
1. Mark `@ez.thread` as deprecated by emitting `DeprecationWarning` when the decorator is applied.
13+
2. Update docs to indicate deprecation and migration guidance.
14+
3. Add tests to ensure the warning is emitted and existing decorator behavior remains intact for compatibility.
15+
16+
## Non-Goals
17+
- Removing `@ez.thread` in this issue.
18+
- Changing runtime behavior of existing `@ez.thread`-decorated functions beyond warning emission.
19+
20+
## Acceptance Criteria
21+
- Calling `ez.thread(...)` emits `DeprecationWarning`.
22+
- API docs clearly mark `@ez.thread` as deprecated with migration guidance.
23+
- Test coverage exists for warning behavior and attribute tagging.
24+
25+
## Follow-Up
26+
- Remove `@ez.thread` in a future major release after deprecation window.
27+
- Add release note/migration note before removal.

PR_deprecate_ez_thread.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Deprecate `@ez.thread`
2+
3+
## Summary
4+
This changeset deprecates the `@ez.thread` decorator and documents the preferred replacement (`loop.run_in_executor(...)` / explicit task lifecycle management).
5+
6+
## Changes
7+
- Emit `DeprecationWarning` from `ezmsg.core.unit.thread`.
8+
- Add deprecation note to function decorator docs.
9+
- Add a unit test verifying warning emission and backward-compatible decorator tagging.
10+
11+
## Files
12+
- `src/ezmsg/core/unit.py`
13+
- `docs/source/reference/API/functiondecorators.rst`
14+
- `tests/test_unit_deprecations.py`
15+
- `ISSUE_deprecate_ez_thread.md`
16+
17+
## Testing
18+
- `PYTHONPYCACHEPREFIX=/tmp/pycache .venv/bin/pytest tests/test_unit_deprecations.py -q`
19+
20+
## Backward Compatibility
21+
- Existing `@ez.thread` usage continues to function in this release.
22+
- Users now receive a deprecation warning at decorator application time.
23+
24+
## Future Work
25+
- Remove `@ez.thread` in a future major release after migration window and release-note notice.

docs/source/reference/API/functiondecorators.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ These function decorators can be added to member functions of an ezmsg ``Unit``
1111

1212
.. autodecorator:: ezmsg.core.thread
1313

14+
.. note::
15+
``@ez.thread`` is deprecated and will be removed in a future release.
16+
Prefer explicit background work via ``loop.run_in_executor(...)``.
17+
1418
.. autodecorator:: ezmsg.core.task
1519

1620
.. autodecorator:: ezmsg.core.process

src/ezmsg/core/unit.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,22 @@ def thread(func: Callable):
274274
Thread functions run concurrently with the main message processing and can be used
275275
for background tasks, monitoring, or other concurrent operations.
276276
277+
.. deprecated::
278+
``@thread`` is deprecated and will be removed in a future release.
279+
Prefer explicit background work using ``loop.run_in_executor(...)`` or
280+
explicit task management in ``initialize()``/``shutdown()``.
281+
277282
:param func: The function to run as a background thread
278283
:type func: collections.abc.Callable
279284
:return: The decorated function
280285
:rtype: collections.abc.Callable
281286
"""
287+
warnings.warn(
288+
"`@ez.thread` is deprecated and will be removed in a future release. "
289+
"Prefer explicit background work via `loop.run_in_executor(...)`.",
290+
DeprecationWarning,
291+
stacklevel=2,
292+
)
282293
setattr(func, THREAD_ATTR, True)
283294
return func
284295

tests/test_unit_deprecations.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
import ezmsg.core as ez
4+
from ezmsg.core.unit import THREAD_ATTR
5+
6+
7+
def test_thread_decorator_warns_and_sets_attribute():
8+
def fn(_):
9+
return None
10+
11+
with pytest.warns(
12+
DeprecationWarning,
13+
match=r"`@ez\.thread` is deprecated and will be removed in a future release",
14+
):
15+
decorated = ez.thread(fn)
16+
17+
assert decorated is fn
18+
assert hasattr(decorated, THREAD_ATTR)

0 commit comments

Comments
 (0)