From d938427d67685efbf07f8d44e4662f9c74b40bc8 Mon Sep 17 00:00:00 2001 From: "Nathaniel J. Smith" Date: Sun, 24 Dec 2017 19:46:58 -0800 Subject: [PATCH] Remove Queue.join and Queue.task_done Deprecated in 0.2.0 (see gh-321) --- trio/_sync.py | 33 --------------------------------- trio/tests/test_sync.py | 36 +----------------------------------- 2 files changed, 1 insertion(+), 68 deletions(-) diff --git a/trio/_sync.py b/trio/_sync.py index d42f613f71..9e6fac062c 100644 --- a/trio/_sync.py +++ b/trio/_sync.py @@ -5,7 +5,6 @@ from . import _core from ._util import aiter_compat -from ._deprecate import deprecated __all__ = [ "Event", @@ -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 @@ -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 ( @@ -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 @@ -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 @@ -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 ) diff --git a/trio/tests/test_sync.py b/trio/tests/test_sync.py index 024dce39ac..7523005ce2 100644 --- a/trio/tests/test_sync.py +++ b/trio/tests/test_sync.py @@ -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) @@ -459,8 +430,7 @@ 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() @@ -468,7 +438,6 @@ async def test_Queue_statistics(recwarn): 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) @@ -476,14 +445,12 @@ async def test_Queue_statistics(recwarn): 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) @@ -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()