diff --git a/src/trio/_core/_parking_lot.py b/src/trio/_core/_parking_lot.py index 9fea4e5b2..9dd3b42dd 100644 --- a/src/trio/_core/_parking_lot.py +++ b/src/trio/_core/_parking_lot.py @@ -269,11 +269,13 @@ def repark_all(self, new_lot: ParkingLot) -> None: """ return self.repark(new_lot, count=len(self)) - def break_lot(self, task: Task | None) -> None: + def break_lot(self, task: Task | None = None) -> None: """Break this lot, causing all parked tasks to raise an error, and any future tasks attempting to park (and unpark? repark?) to error. The error contains a reference to the task sent as a parameter. """ + if task is None: + task = _core.current_task() self.broken_by = task for parked_task in self._parked: diff --git a/src/trio/_core/_tests/test_parking_lot.py b/src/trio/_core/_tests/test_parking_lot.py index 740b0412c..5bfd00912 100644 --- a/src/trio/_core/_tests/test_parking_lot.py +++ b/src/trio/_core/_tests/test_parking_lot.py @@ -240,6 +240,9 @@ async def test_parking_lot_breaker_basic() -> None: ): trio.lowlevel.remove_parking_lot_breaker(task, lot) + lot.break_lot() + assert lot.broken_by == task + async def test_parking_lot_breaker() -> None: async def bad_parker(lot: ParkingLot, scope: _core.CancelScope) -> None: