Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Pub and Sub #8724

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion distributed/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import weakref
from collections import defaultdict, deque

from dask.utils import parse_timedelta
from dask.utils import _deprecated, parse_timedelta

from distributed.core import CommClosedError
from distributed.metrics import time
Expand Down Expand Up @@ -198,6 +198,7 @@ def cleanup(self):
self.client.scheduler_comm.send(msg)


@_deprecated(use_instead="Client.log_event() or Worker.log_event()")
class Pub:
"""Publish data with Publish-Subscribe pattern

Expand Down Expand Up @@ -354,6 +355,7 @@ def __repr__(self):
__str__ = __repr__


@_deprecated(use_instead="Client.subscribe_topic()")
class Sub:
"""Subscribe to a Publish/Subscribe topic

Expand Down
33 changes: 22 additions & 11 deletions distributed/tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ async def test_speed(c, s, a, b):
"""

def pingpong(a, b, start=False, n=1000, msg=1):
sub = Sub(a)
pub = Pub(b)
with pytest.warns(FutureWarning, match="deprecated"):
sub = Sub(a)
with pytest.warns(FutureWarning, match="deprecated"):
pub = Pub(b)

while not pub.subscribers:
sleep(0.01)
Expand Down Expand Up @@ -56,8 +58,10 @@ def pingpong(a, b, start=False, n=1000, msg=1):
async def test_client(c, s):
with pytest.raises(ValueError, match="No worker found"):
get_worker()
sub = Sub("a")
pub = Pub("a")
with pytest.warns(FutureWarning, match="deprecated"):
sub = Sub("a")
with pytest.warns(FutureWarning, match="deprecated"):
pub = Pub("a")

sps = s.extensions["pubsub"]
cps = c.extensions["pubsub"]
Expand All @@ -75,10 +79,12 @@ async def test_client(c, s):

@gen_cluster(client=True)
async def test_client_worker(c, s, a, b):
sub = Sub("a", client=c, worker=None)
with pytest.warns(FutureWarning, match="deprecated"):
sub = Sub("a", client=c, worker=None)

def f(x):
pub = Pub("a")
with pytest.warns(FutureWarning, match="deprecated"):
pub = Pub("a")
pub.put(x)

futures = c.map(f, range(10))
Expand Down Expand Up @@ -120,7 +126,8 @@ def f(x):

@gen_cluster(client=True)
async def test_timeouts(c, s, a, b):
sub = Sub("a", client=c, worker=None)
with pytest.warns(FutureWarning, match="deprecated"):
sub = Sub("a", client=c, worker=None)
start = time()
with pytest.raises(TimeoutError):
await sub.get(timeout="100ms")
Expand All @@ -132,8 +139,10 @@ async def test_timeouts(c, s, a, b):

@gen_cluster(client=True)
async def test_repr(c, s, a, b):
pub = Pub("my-topic")
sub = Sub("my-topic")
with pytest.warns(FutureWarning, match="deprecated"):
pub = Pub("my-topic")
with pytest.warns(FutureWarning, match="deprecated"):
sub = Sub("my-topic")
assert "my-topic" in str(pub)
assert "Pub" in str(pub)
assert "my-topic" in str(sub)
Expand All @@ -144,7 +153,8 @@ async def test_repr(c, s, a, b):
@gen_cluster(client=True)
async def test_basic(c, s, a, b):
async def publish():
pub = Pub("a")
with pytest.warns(FutureWarning, match="deprecated"):
pub = Pub("a")

i = 0
while True:
Expand All @@ -153,7 +163,8 @@ async def publish():
i += 1

def f(_):
sub = Sub("a")
with pytest.warns(FutureWarning, match="deprecated"):
sub = Sub("a")
return list(toolz.take(5, sub))

asyncio.ensure_future(c.run(publish, workers=[a.address]))
Expand Down
Loading