Skip to content

Commit cc97cca

Browse files
committed
remove warning on task exit
1 parent 7a1ce5b commit cc97cca

File tree

2 files changed

+17
-37
lines changed

2 files changed

+17
-37
lines changed

src/trio/_core/_run.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,8 @@ def task_exited(self, task: Task, outcome: Outcome[Any]) -> None:
19001900
# break parking lots associated with the task exiting
19011901
if task in GLOBAL_PARKING_LOT_BREAKER:
19021902
for lot in GLOBAL_PARKING_LOT_BREAKER[task]:
1903-
lot.break_lot(task)
1903+
if lot.broken_by is None:
1904+
lot.break_lot(task)
19041905
del GLOBAL_PARKING_LOT_BREAKER[task]
19051906

19061907
if (
@@ -2800,8 +2801,6 @@ def unrolled_run(
28002801
),
28012802
stacklevel=1,
28022803
)
2803-
except RuntimeWarning:
2804-
raise
28052804
except TrioInternalError:
28062805
raise
28072806
except BaseException as exc:

src/trio/_core/_tests/test_parking_lot.py

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,12 @@ async def test_parking_lot_breaker_basic() -> None:
261261
# breaking the lot again with the same task is a no-op
262262
lot.break_lot()
263263

264+
# registering a task as a breaker on an already broken lot is a no-op.
264265
child_task = None
265-
with pytest.warns(RuntimeWarning):
266-
async with trio.open_nursery() as nursery:
267-
child_task = await nursery.start(dummy_task)
268-
# registering a task as breaker on an already broken lot is fine... though it
269-
# maybe shouldn't be as it will always cause a RuntimeWarning???
270-
# Or is this a sign that we shouldn't raise a warning?
271-
add_parking_lot_breaker(child_task, lot)
272-
nursery.cancel_scope.cancel()
266+
async with trio.open_nursery() as nursery:
267+
child_task = await nursery.start(dummy_task)
268+
add_parking_lot_breaker(child_task, lot)
269+
nursery.cancel_scope.cancel()
273270

274271
# manually breaking a lot with an already exited task is fine
275272
lot = ParkingLot()
@@ -293,37 +290,21 @@ async def test_parking_lot_breaker_warnings() -> None:
293290
lot.break_lot(child_task)
294291
nursery.cancel_scope.cancel()
295292

296-
# note that this get put into an exceptiongroup if inside a nursery, making any
297-
# stacklevel arguments irrelevant
298-
with RaisesGroup(Matcher(RuntimeWarning, match=warn_str)):
299-
async with trio.open_nursery() as nursery:
300-
child_task = await nursery.start(dummy_task)
301-
lot.break_lot(child_task)
302-
nursery.cancel_scope.cancel()
303-
304293
# and doesn't change broken_by
305294
assert lot.broken_by == task
306295

307296
# register multiple tasks as lot breakers, then have them all exit
297+
# No warning is given on task exit, even if the lot is already broken.
308298
lot = ParkingLot()
309299
child_task = None
310-
# This does not give an exception group, as the warning is raised by the nursery
311-
# exiting, and not any of the tasks inside the nursery.
312-
# And we only get a single warning because... of the default warning filter? and the
313-
# location being the same? (because I haven't figured out why stacklevel makes no
314-
# difference)
315-
with pytest.warns(
316-
RuntimeWarning,
317-
match=warn_str,
318-
):
319-
async with trio.open_nursery() as nursery:
320-
child_task = await nursery.start(dummy_task)
321-
child_task2 = await nursery.start(dummy_task)
322-
child_task3 = await nursery.start(dummy_task)
323-
add_parking_lot_breaker(child_task, lot)
324-
add_parking_lot_breaker(child_task2, lot)
325-
add_parking_lot_breaker(child_task3, lot)
326-
nursery.cancel_scope.cancel()
300+
async with trio.open_nursery() as nursery:
301+
child_task = await nursery.start(dummy_task)
302+
child_task2 = await nursery.start(dummy_task)
303+
child_task3 = await nursery.start(dummy_task)
304+
add_parking_lot_breaker(child_task, lot)
305+
add_parking_lot_breaker(child_task2, lot)
306+
add_parking_lot_breaker(child_task3, lot)
307+
nursery.cancel_scope.cancel()
327308

328309
# trying to register an exited task as lot breaker errors
329310
with pytest.raises(
@@ -333,7 +314,7 @@ async def test_parking_lot_breaker_warnings() -> None:
333314
add_parking_lot_breaker(child_task, lot)
334315

335316

336-
async def test_parking_lot_breaker() -> None:
317+
async def test_parking_lot_breaker_bad_parker() -> None:
337318
async def bad_parker(lot: ParkingLot, scope: _core.CancelScope) -> None:
338319
add_parking_lot_breaker(current_task(), lot)
339320
with scope:

0 commit comments

Comments
 (0)