Skip to content

Commit

Permalink
Nursery: don't act as a checkpoint when not running anything
Browse files Browse the repository at this point in the history
Previously, a Nursery would checkpoint on exit, regardless of whether
it was running anything. This is a bit annoying, see python-trio#1457, so let's
change it to not checkpoint on exit. Now it won't be a checkpoint at
all if there's no tasks running inside.

However, this doesn't fully solve python-trio#1457, because we'll still inject a
cancel even if none of the child tasks raise Cancelled.

This seems to break
trio/_core/tests/test_asyncgen.py::test_last_minute_gc_edge_case
such that it no longer ever hits the edge case.

That seems like a pretty complicated test, so maybe @oremanj can say
better why exactly it's breaking with this change.
  • Loading branch information
catern committed Aug 26, 2020
1 parent a45031e commit 68c9364
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
8 changes: 0 additions & 8 deletions trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,14 +925,6 @@ def aborted(raise_cancel):

self._parent_waiting_in_aexit = True
await wait_task_rescheduled(aborted)
else:
# Nothing to wait for, so just execute a checkpoint -- but we
# still need to mix any exception (e.g. from an external
# cancellation) in with the rest of our exceptions.
try:
await checkpoint()
except BaseException as exc:
self._add_exc(exc)

popped = self._parent_task._child_nurseries.pop()
assert popped is self
Expand Down
10 changes: 3 additions & 7 deletions trio/_core/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
wait_all_tasks_blocked,
Sequencer,
assert_checkpoints,
assert_no_checkpoints,
)


Expand Down Expand Up @@ -1605,20 +1606,15 @@ async def test_trivial_yields():
await _core.checkpoint_if_cancelled()
await _core.cancel_shielded_checkpoint()

with assert_checkpoints():
with assert_no_checkpoints():
async with _core.open_nursery():
pass

with _core.CancelScope() as cancel_scope:
cancel_scope.cancel()
with pytest.raises(_core.MultiError) as excinfo:
with pytest.raises(KeyError):
async with _core.open_nursery():
raise KeyError
assert len(excinfo.value.exceptions) == 2
assert {type(e) for e in excinfo.value.exceptions} == {
KeyError,
_core.Cancelled,
}


async def test_nursery_start(autojump_clock):
Expand Down

0 comments on commit 68c9364

Please sign in to comment.