Skip to content

Commit

Permalink
Remove Queue.join and Queue.task_done
Browse files Browse the repository at this point in the history
Deprecated in 0.2.0 (see python-triogh-321)
  • Loading branch information
njsmith committed Dec 25, 2017
1 parent b01d9f6 commit d938427
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 68 deletions.
33 changes: 0 additions & 33 deletions trio/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from . import _core
from ._util import aiter_compat
from ._deprecate import deprecated

__all__ = [
"Event",
Expand Down Expand Up @@ -800,7 +799,6 @@ class _QueueStats:
capacity = attr.ib()
tasks_waiting_put = attr.ib()
tasks_waiting_get = attr.ib()
tasks_waiting_join = attr.ib()


# Like queue.Queue, with the notable difference that the capacity argument is
Expand Down Expand Up @@ -841,8 +839,6 @@ def __init__(self, capacity):
self._put_semaphore = Semaphore(capacity, max_value=capacity)
self._get_semaphore = Semaphore(0, max_value=capacity)
self._data = deque()
self._join_lot = _core.ParkingLot()
self._unprocessed = 0

def __repr__(self):
return (
Expand Down Expand Up @@ -879,7 +875,6 @@ def empty(self):

def _put_protected(self, obj):
self._data.append(obj)
self._unprocessed += 1
self._get_semaphore.release()

@_core.enable_ki_protection
Expand Down Expand Up @@ -936,33 +931,6 @@ async def get(self):
await self._get_semaphore.acquire()
return self._get_protected()

@deprecated("0.2.0", issue=321, instead=None)
@_core.enable_ki_protection
def task_done(self):
"""Decrement the count of unfinished work.
Each :class:`Queue` object keeps a count of unfinished work, which
starts at zero and is incremented after each successful
:meth:`put`. This method decrements it again. When the count reaches
zero, any tasks blocked in :meth:`join` are woken.
"""
self._unprocessed -= 1
if self._unprocessed == 0:
self._join_lot.unpark_all()

@deprecated("0.2.0", issue=321, instead=None)
async def join(self):
"""Block until the count of unfinished work reaches zero.
See :meth:`task_done` for details.
"""
if self._unprocessed == 0:
await _core.checkpoint()
else:
await self._join_lot.park()

@aiter_compat
def __aiter__(self):
return self
Expand All @@ -988,5 +956,4 @@ def statistics(self):
capacity=self.capacity,
tasks_waiting_put=self._put_semaphore.statistics().tasks_waiting,
tasks_waiting_get=self._get_semaphore.statistics().tasks_waiting,
tasks_waiting_join=self._join_lot.statistics().tasks_waiting
)
36 changes: 1 addition & 35 deletions trio/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,35 +410,6 @@ async def test_Queue():
assert q.empty()


async def test_Queue_join(recwarn):
q = Queue(2)
with assert_checkpoints():
await q.join()

record = []

async def do_join(q):
record.append("started")
await q.join()
record.append("finished")

async with _core.open_nursery() as nursery:
await q.put(None)
nursery.start_soon(do_join, q)
nursery.start_soon(do_join, q)
await wait_all_tasks_blocked()
assert record == ["started", "started"]
q.put_nowait(None)
q.get_nowait()
q.get_nowait()
q.task_done()
await wait_all_tasks_blocked()
assert record == ["started", "started"]
q.task_done()

assert record == ["started", "started", "finished", "finished"]


async def test_Queue_iter():
q = Queue(1)

Expand All @@ -459,31 +430,27 @@ async def consumer():
nursery.start_soon(consumer)


# XX remove the 'recwarn' fixture after join is removed
async def test_Queue_statistics(recwarn):
async def test_Queue_statistics():
q = Queue(3)
q.put_nowait(1)
statistics = q.statistics()
assert statistics.qsize == 1
assert statistics.capacity == 3
assert statistics.tasks_waiting_put == 0
assert statistics.tasks_waiting_get == 0
assert statistics.tasks_waiting_join == 0

async with _core.open_nursery() as nursery:
q.put_nowait(2)
q.put_nowait(3)
assert q.full()
nursery.start_soon(q.put, 4)
nursery.start_soon(q.put, 5)
nursery.start_soon(q.join)
await wait_all_tasks_blocked()
statistics = q.statistics()
assert statistics.qsize == 3
assert statistics.capacity == 3
assert statistics.tasks_waiting_put == 2
assert statistics.tasks_waiting_get == 0
assert statistics.tasks_waiting_join == 1
nursery.cancel_scope.cancel()

q = Queue(4)
Expand All @@ -497,7 +464,6 @@ async def test_Queue_statistics(recwarn):
assert statistics.capacity == 4
assert statistics.tasks_waiting_put == 0
assert statistics.tasks_waiting_get == 3
assert statistics.tasks_waiting_join == 0
nursery.cancel_scope.cancel()


Expand Down

0 comments on commit d938427

Please sign in to comment.