Skip to content

Commit ec48863

Browse files
committed
docstring updates after A5rocks review
1 parent 45f78f4 commit ec48863

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

src/trio/_core/_parking_lot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,15 @@
9292

9393

9494
def add_parking_lot_breaker(task: Task, lot: ParkingLot) -> None:
95-
"""Register a task as a breaker for a lot. If this task exits without being removed
96-
as a breaker, the lot will break. This will cause an error to be raised for all
97-
tasks currently parked in the lot, as well as any future tasks that attempt to
98-
park in it.
99-
"""
95+
"""Register a task as a breaker for a lot. See :meth:`ParkingLot.break_lot`"""
10096
if task not in GLOBAL_PARKING_LOT_BREAKER:
10197
GLOBAL_PARKING_LOT_BREAKER[task] = [lot]
10298
else:
10399
GLOBAL_PARKING_LOT_BREAKER[task].append(lot)
104100

105101

106102
def remove_parking_lot_breaker(task: Task, lot: ParkingLot) -> None:
107-
"""Deregister a task as a breaker for a lot. See :func:`add_parking_lot_breaker`."""
103+
"""Deregister a task as a breaker for a lot. See :meth:`ParkingLot.break_lot`"""
108104
try:
109105
GLOBAL_PARKING_LOT_BREAKER[task].remove(lot)
110106
except (KeyError, ValueError):
@@ -273,10 +269,14 @@ def repark_all(self, new_lot: ParkingLot) -> None:
273269
return self.repark(new_lot, count=len(self))
274270

275271
def break_lot(self, task: Task | None = None) -> None:
276-
"""Break this lot, causing all parked tasks to raise an error, and any
272+
"""Break this lot, with ``task`` noted as the task that broke it.
273+
274+
This causes all parked tasks to raise an error, and any
277275
future tasks attempting to park to error. Unpark & repark become no-ops as the
278276
parking lot is empty.
279-
The error raised contains a reference to the task sent as a parameter.
277+
278+
The error raised contains a reference to the task sent as a parameter. It is also
279+
saved in the ``broken_by`` attribute.
280280
"""
281281
if task is None:
282282
task = _core.current_task()

src/trio/_core/_run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,7 @@ async def python_wrapper(orig_coro: Awaitable[RetT]) -> RetT:
18211821
return task
18221822

18231823
def task_exited(self, task: Task, outcome: Outcome[Any]) -> None:
1824+
# break parking lots associated with the task exiting
18241825
if task in GLOBAL_PARKING_LOT_BREAKER:
18251826
for lot in GLOBAL_PARKING_LOT_BREAKER[task]:
18261827
lot.break_lot(task)

src/trio/_core/_tests/test_parking_lot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ async def return_me_and_park(
310310
await lot.park()
311311

312312
lot = ParkingLot()
313-
with RaisesGroup(Matcher(_core.BrokenResourceError, match="Parking lot broken by")):
313+
with RaisesGroup(
314+
Matcher(_core.BrokenResourceError, match="^Parking lot broken by"),
315+
):
314316
async with _core.open_nursery() as nursery:
315317
task = await nursery.start(return_me_and_park, lot)
316318
lot.break_lot(task)

src/trio/_sync.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
import trio
99

1010
from . import _core
11-
from ._core import Abort, ParkingLot, RaiseCancelT, enable_ki_protection
12-
from ._core._parking_lot import add_parking_lot_breaker, remove_parking_lot_breaker
11+
from ._core import (
12+
Abort,
13+
ParkingLot,
14+
RaiseCancelT,
15+
add_parking_lot_breaker,
16+
enable_ki_protection,
17+
remove_parking_lot_breaker,
18+
)
1319
from ._util import final
1420

1521
if TYPE_CHECKING:
@@ -599,7 +605,7 @@ async def acquire(self) -> None:
599605
await self._lot.park()
600606
except trio.BrokenResourceError:
601607
raise trio.BrokenResourceError(
602-
"Owner of this lock exited without releasing: {self._owner}",
608+
f"Owner of this lock exited without releasing: {self._owner}",
603609
) from None
604610
else:
605611
await trio.lowlevel.cancel_shielded_checkpoint()

src/trio/_tests/test_sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ async def lock_taker() -> None:
593593

594594
async def test_lock_acquire_unowned_lock() -> None:
595595
"""Test that trying to acquire a lock whose owner has exited raises an error.
596-
Partial fix for https://github.com/python-trio/trio/issues/3035
596+
see https://github.com/python-trio/trio/issues/3035
597597
"""
598598
assert not GLOBAL_PARKING_LOT_BREAKER
599599
lock = trio.Lock()
@@ -608,6 +608,8 @@ async def test_lock_acquire_unowned_lock() -> None:
608608

609609

610610
async def test_lock_multiple_acquire() -> None:
611+
"""Test for error if awaiting on a lock whose owner exits without releasing.
612+
see https://github.com/python-trio/trio/issues/3035"""
611613
assert not GLOBAL_PARKING_LOT_BREAKER
612614
lock = trio.Lock()
613615
with RaisesGroup(

0 commit comments

Comments
 (0)