Skip to content

Commit

Permalink
PEP 789: minor clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed May 27, 2024
1 parent a2cb879 commit c1a2d27
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions peps/pep-0789.rst
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,9 @@ yield-within-with problems are not exclusive to async generators:
yield
one = decimal.Decimal(1)
x = one / 3
print(one / 3) # 0.3333333333333333333333333333
next(gen := why_would_you_do_this())
y = one / 3
print(x) # 0.3333333333333333333333333333
print(y) # 0.3
print(one / 3) # 0.3
While I've had good experiences in async Python without async generators
Expand Down Expand Up @@ -680,13 +678,15 @@ concurrency is that your stack becomes a tree, with child tasks encapsulated
within some parent frame. They're extending the basic structured programming
model in different, and unfortunately incompatible, directions.

Note that ``TaskGroup`` *would* play nicely with generators if suspending the
frame with the context manager also suspended all child tasks. Note also that
this would cause all of our motivating examples to deadlock, as we wait for
values to be produced by suspended child tasks - a prohibitive design problem.
Suppose for example that suspending a frame containing an open ``TaskGroup``
also suspended all child tasks. This would preserve the 'downward' structured
concurrency, in that children remain encapsulated - albeit at the cost of
deadlocking both of our motivating examples, and much real-world code.
However, it would still be possible to resume the generator in a different
task, violating the 'upwards' invariant of structured concurrency.

We don't think it's worth adding this much machinery to handle cancel scopes,
while leaving task groups (and no-exception cases) broken.
while still leaving task groups broken.


Alternative implementation - inspecting bytecode
Expand Down

0 comments on commit c1a2d27

Please sign in to comment.