Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How to Master Python asyncio.TaskGroup in Punggol Tuition

HDB refuse collection point and void deck at Block 288C in Punggol

When a learner can reproduce a familiar example but a small variation causes confusion, the problem is usually an incomplete model rather than a lack of effort. The fastest useful response is to expose the hidden state and test one boundary at a time.

Python asyncio.TaskGroup is an asynchronous context manager for structured concurrency. It was added in Python 3.11: tasks created through the group belong to one lexical lifetime, the context waits for all of them, and an ordinary failure cancels remaining siblings before the failures are raised together. Mastery means knowing who owns each task, preserving cancellation during cleanup, reading ExceptionGroup deliberately, distinguishing TaskGroup from gather(), and checking newer conveniences—such as TaskGroup.cancel(), added in Python 3.15—against the interpreter actually deployed. This guide begins with that mechanism, then develops it through worked traces, deliberate mistakes, explained practice and transfer decisions.

The aim is independent reasoning. A learner should be able to predict behaviour, locate the earliest wrong assumption, use a safe diagnostic procedure and defend a design choice in a new project.

Punggol families can use the guide in short sessions around homework, CCAs and rest. The activities are proposed learning exercises, not claims about a physical branch, timetable, class size, fee, school relationship or guaranteed result.

Use disposable data and repositories, preserve backups, and check version-sensitive details against the official source. Current documentation settles a technical contract; observation and explanation turn that contract into usable knowledge.

Find your next learning step

Choose the route that matches the present difficulty. Use the complete index for a systematic course.

Build the model

Chapters 1-4 . Begin here, then continue after the learner can predict, verify and explain.

Use the core tools

Chapters 5-8 . Begin here, then continue after the learner can predict, verify and explain.

Handle boundaries

Chapters 9-12 . Begin here, then continue after the learner can predict, verify and explain.

Debug and verify

Chapters 13-16 . Begin here, then continue after the learner can predict, verify and explain.

Transfer with judgment

Chapters 17-20 . Begin here, then continue after the learner can predict, verify and explain.

Open the full chapter index . Jump to capstone practice . Use the How Studying Works hub . Read the official documentation

CHAPTER 1 OF 20 . Build the model

1. TaskGroup owns a lexical task lifetime

Back to contents

An async with block establishes a scope in which child tasks are created and completed before control leaves. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is creating background work inside a group and expecting it to outlive the context. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for TaskGroup owns a lexical task lifetime, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the TaskGroup owns a lexical task lifetime chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on creating background work inside a group and expecting it to outlive the context. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as tg:
    tg.create_task(load_notes())
print('all group tasks finished')

Explained result. The print runs only after the child has finished or the group has completed its failure protocol. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: homework dashboard. Predict the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “An async with block establishes a scope in which child tasks are created and completed before control leaves.” Apply this procedure: State the contract for TaskGroup owns a lexical task lifetime, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The print runs only after the child has finished or the group has completed its failure protocol. For the homework dashboard, add one near-miss that exposes creating background work inside a group and expecting it to outlive the context. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: reading tracker. Contrast the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “An async with block establishes a scope in which child tasks are created and completed before control leaves.” Apply this procedure: State the contract for TaskGroup owns a lexical task lifetime, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The print runs only after the child has finished or the group has completed its failure protocol. For the reading tracker, add one near-miss that exposes creating background work inside a group and expecting it to outlive the context. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: science project. Stress-test the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “An async with block establishes a scope in which child tasks are created and completed before control leaves.” Apply this procedure: State the contract for TaskGroup owns a lexical task lifetime, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The print runs only after the child has finished or the group has completed its failure protocol. For the science project, add one near-miss that exposes creating background work inside a group and expecting it to outlive the context. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: CCA registration. Explain the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “An async with block establishes a scope in which child tasks are created and completed before control leaves.” Apply this procedure: State the contract for TaskGroup owns a lexical task lifetime, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The print runs only after the child has finished or the group has completed its failure protocol. For the CCA registration, add one near-miss that exposes creating background work inside a group and expecting it to outlive the context. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers creating background work inside a group and expecting it to outlive the context.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for TaskGroup owns a lexical task lifetime, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from TaskGroup owns a lexical task lifetime?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing creating background work inside a group and expecting it to outlive the context be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny library catalogue with nested groups separate book-level failures from batch-level cancellation. Include one ordinary case, one boundary and one deliberate failure caused by creating background work inside a group and expecting it to outlive the context. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: An async with block establishes a scope in which child tasks are created and completed before control leaves. It shows a trace, not only a final value. The ordinary case should demonstrate “The print runs only after the child has finished or the group has completed its failure protocol.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for TaskGroup owns a lexical task lifetime, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For TaskGroup owns a lexical task lifetime, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 2 OF 20 . Build the model

2. Python 3.11 is the availability boundary

Back to contents

asyncio.TaskGroup entered the standard library in Python 3.11, so older deployments need a different design or explicit compatibility layer. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is testing on a new interpreter and assuming every school or server environment provides it. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Python 3.11 is the availability boundary, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Python 3.11 is the availability boundary chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on testing on a new interpreter and assuming every school or server environment provides it. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

import sys, asyncio
print(sys.version_info[:2], hasattr(asyncio,'TaskGroup'))

Explained result. The local version and attribute check expose the deployment boundary before code is released. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: science project. Contrast the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio.TaskGroup entered the standard library in Python 3.11, so older deployments need a different design or explicit compatibility layer.” Apply this procedure: State the contract for Python 3.11 is the availability boundary, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The local version and attribute check expose the deployment boundary before code is released. For the science project, add one near-miss that exposes testing on a new interpreter and assuming every school or server environment provides it. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: CCA registration. Stress-test the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio.TaskGroup entered the standard library in Python 3.11, so older deployments need a different design or explicit compatibility layer.” Apply this procedure: State the contract for Python 3.11 is the availability boundary, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The local version and attribute check expose the deployment boundary before code is released. For the CCA registration, add one near-miss that exposes testing on a new interpreter and assuming every school or server environment provides it. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: family planner. Explain the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio.TaskGroup entered the standard library in Python 3.11, so older deployments need a different design or explicit compatibility layer.” Apply this procedure: State the contract for Python 3.11 is the availability boundary, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The local version and attribute check expose the deployment boundary before code is released. For the family planner, add one near-miss that exposes testing on a new interpreter and assuming every school or server environment provides it. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: library catalogue. Transfer the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio.TaskGroup entered the standard library in Python 3.11, so older deployments need a different design or explicit compatibility layer.” Apply this procedure: State the contract for Python 3.11 is the availability boundary, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The local version and attribute check expose the deployment boundary before code is released. For the library catalogue, add one near-miss that exposes testing on a new interpreter and assuming every school or server environment provides it. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers testing on a new interpreter and assuming every school or server environment provides it.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Python 3.11 is the availability boundary, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Python 3.11 is the availability boundary?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing testing on a new interpreter and assuming every school or server environment provides it be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny test laboratory with success, failure, cancellation, timeout and nested groups are observed on a disposable loop. Include one ordinary case, one boundary and one deliberate failure caused by testing on a new interpreter and assuming every school or server environment provides it. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: asyncio.TaskGroup entered the standard library in Python 3.11, so older deployments need a different design or explicit compatibility layer. It shows a trace, not only a final value. The ordinary case should demonstrate “The local version and attribute check expose the deployment boundary before code is released.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Python 3.11 is the availability boundary, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Python 3.11 is the availability boundary, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 3 OF 20 . Build the model

3. create_task returns the child Task

Back to contents

TaskGroup.create_task schedules the coroutine and returns a Task whose result can be read after the group exits successfully. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is discarding every returned task and then rerunning work merely to obtain results. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for create_task returns the child Task, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the create_task returns the child Task chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on discarding every returned task and then rerunning work merely to obtain results. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as tg:
    a=tg.create_task(score('math'))
print(a.result())

Explained result. After successful exit, a is done and result() returns the child value. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: family planner. Stress-test the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup.create_task schedules the coroutine and returns a Task whose result can be read after the group exits successfully.” Apply this procedure: State the contract for create_task returns the child Task, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: After successful exit, a is done and result() returns the child value. For the family planner, add one near-miss that exposes discarding every returned task and then rerunning work merely to obtain results. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: library catalogue. Explain the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup.create_task schedules the coroutine and returns a Task whose result can be read after the group exits successfully.” Apply this procedure: State the contract for create_task returns the child Task, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: After successful exit, a is done and result() returns the child value. For the library catalogue, add one near-miss that exposes discarding every returned task and then rerunning work merely to obtain results. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: test laboratory. Transfer the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup.create_task schedules the coroutine and returns a Task whose result can be read after the group exits successfully.” Apply this procedure: State the contract for create_task returns the child Task, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: After successful exit, a is done and result() returns the child value. For the test laboratory, add one near-miss that exposes discarding every returned task and then rerunning work merely to obtain results. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: design decision. Predict the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup.create_task schedules the coroutine and returns a Task whose result can be read after the group exits successfully.” Apply this procedure: State the contract for create_task returns the child Task, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: After successful exit, a is done and result() returns the child value. For the design decision, add one near-miss that exposes discarding every returned task and then rerunning work merely to obtain results. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers discarding every returned task and then rerunning work merely to obtain results.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for create_task returns the child Task, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from create_task returns the child Task?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing discarding every returned task and then rerunning work merely to obtain results be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny design decision with TaskGroup is compared with gather, create_task without ownership and a durable job queue. Include one ordinary case, one boundary and one deliberate failure caused by discarding every returned task and then rerunning work merely to obtain results. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: TaskGroup.create_task schedules the coroutine and returns a Task whose result can be read after the group exits successfully. It shows a trace, not only a final value. The ordinary case should demonstrate “After successful exit, a is done and result() returns the child value.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for create_task returns the child Task, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For create_task returns the child Task, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 4 OF 20 . Build the model

4. Context exit waits implicitly

Back to contents

No separate gather call is required merely to wait for all tasks created in the active group. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is adding a second wait layer and obscuring which scope owns completion. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Context exit waits implicitly, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Context exit waits implicitly chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on adding a second wait layer and obscuring which scope owns completion. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as tg:
    for n in names: tg.create_task(check(n))

Explained result. Leaving the block is the documented join point for every child accepted by the group. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: test laboratory. Explain the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “No separate gather call is required merely to wait for all tasks created in the active group.” Apply this procedure: State the contract for Context exit waits implicitly, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Leaving the block is the documented join point for every child accepted by the group. For the test laboratory, add one near-miss that exposes adding a second wait layer and obscuring which scope owns completion. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: design decision. Transfer the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “No separate gather call is required merely to wait for all tasks created in the active group.” Apply this procedure: State the contract for Context exit waits implicitly, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Leaving the block is the documented join point for every child accepted by the group. For the design decision, add one near-miss that exposes adding a second wait layer and obscuring which scope owns completion. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: homework dashboard. Predict the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “No separate gather call is required merely to wait for all tasks created in the active group.” Apply this procedure: State the contract for Context exit waits implicitly, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Leaving the block is the documented join point for every child accepted by the group. For the homework dashboard, add one near-miss that exposes adding a second wait layer and obscuring which scope owns completion. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: reading tracker. Contrast the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “No separate gather call is required merely to wait for all tasks created in the active group.” Apply this procedure: State the contract for Context exit waits implicitly, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Leaving the block is the documented join point for every child accepted by the group. For the reading tracker, add one near-miss that exposes adding a second wait layer and obscuring which scope owns completion. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers adding a second wait layer and obscuring which scope owns completion.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Context exit waits implicitly, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Context exit waits implicitly?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing adding a second wait layer and obscuring which scope owns completion be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny homework dashboard with three independent subject summaries are fetched under one visible request. Include one ordinary case, one boundary and one deliberate failure caused by adding a second wait layer and obscuring which scope owns completion. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: No separate gather call is required merely to wait for all tasks created in the active group. It shows a trace, not only a final value. The ordinary case should demonstrate “Leaving the block is the documented join point for every child accepted by the group.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Context exit waits implicitly, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Context exit waits implicitly, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 5 OF 20 . Use the core tools

5. Tasks may add tasks while the group is active

Back to contents

A child can receive the active group and create more children before the last task finishes. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is assuming the membership list is frozen at entry. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Tasks may add tasks while the group is active, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Tasks may add tasks while the group is active chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on assuming the membership list is frozen at entry. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async def parent(tg):
    tg.create_task(child())
async with asyncio.TaskGroup() as tg:
    tg.create_task(parent(tg))

Explained result. The nested child is part of the same group and must finish before exit. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: homework dashboard. Transfer the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A child can receive the active group and create more children before the last task finishes.” Apply this procedure: State the contract for Tasks may add tasks while the group is active, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The nested child is part of the same group and must finish before exit. For the homework dashboard, add one near-miss that exposes assuming the membership list is frozen at entry. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: reading tracker. Predict the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A child can receive the active group and create more children before the last task finishes.” Apply this procedure: State the contract for Tasks may add tasks while the group is active, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The nested child is part of the same group and must finish before exit. For the reading tracker, add one near-miss that exposes assuming the membership list is frozen at entry. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: science project. Contrast the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A child can receive the active group and create more children before the last task finishes.” Apply this procedure: State the contract for Tasks may add tasks while the group is active, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The nested child is part of the same group and must finish before exit. For the science project, add one near-miss that exposes assuming the membership list is frozen at entry. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: CCA registration. Stress-test the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A child can receive the active group and create more children before the last task finishes.” Apply this procedure: State the contract for Tasks may add tasks while the group is active, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The nested child is part of the same group and must finish before exit. For the CCA registration, add one near-miss that exposes assuming the membership list is frozen at entry. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers assuming the membership list is frozen at entry.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Tasks may add tasks while the group is active, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Tasks may add tasks while the group is active?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing assuming the membership list is frozen at entry be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny reading tracker with several book records are checked and one invalid record stops sibling work. Include one ordinary case, one boundary and one deliberate failure caused by assuming the membership list is frozen at entry. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: A child can receive the active group and create more children before the last task finishes. It shows a trace, not only a final value. The ordinary case should demonstrate “The nested child is part of the same group and must finish before exit.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Tasks may add tasks while the group is active, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Tasks may add tasks while the group is active, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 6 OF 20 . Use the core tools

6. Inactive groups reject new work

Back to contents

A group that has not entered, has finished, or is shutting down cannot accept another task; current Python also closes a submitted coroutine in this case from 3.13. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is retaining a TaskGroup object as a reusable global scheduler. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Inactive groups reject new work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Inactive groups reject new work chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on retaining a TaskGroup object as a reusable global scheduler. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

tg=asyncio.TaskGroup()
# tg.create_task(job()) is invalid outside active context

Explained result. TaskGroup is a one-scope owner, not a reusable queue; the exact coroutine-closing improvement is version-sensitive. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: science project. Predict the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A group that has not entered, has finished, or is shutting down cannot accept another task; current Python also closes a submitted coroutine in this case from 3.13.” Apply this procedure: State the contract for Inactive groups reject new work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: TaskGroup is a one-scope owner, not a reusable queue; the exact coroutine-closing improvement is version-sensitive. For the science project, add one near-miss that exposes retaining a TaskGroup object as a reusable global scheduler. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: CCA registration. Contrast the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A group that has not entered, has finished, or is shutting down cannot accept another task; current Python also closes a submitted coroutine in this case from 3.13.” Apply this procedure: State the contract for Inactive groups reject new work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: TaskGroup is a one-scope owner, not a reusable queue; the exact coroutine-closing improvement is version-sensitive. For the CCA registration, add one near-miss that exposes retaining a TaskGroup object as a reusable global scheduler. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: family planner. Stress-test the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A group that has not entered, has finished, or is shutting down cannot accept another task; current Python also closes a submitted coroutine in this case from 3.13.” Apply this procedure: State the contract for Inactive groups reject new work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: TaskGroup is a one-scope owner, not a reusable queue; the exact coroutine-closing improvement is version-sensitive. For the family planner, add one near-miss that exposes retaining a TaskGroup object as a reusable global scheduler. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: library catalogue. Explain the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A group that has not entered, has finished, or is shutting down cannot accept another task; current Python also closes a submitted coroutine in this case from 3.13.” Apply this procedure: State the contract for Inactive groups reject new work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: TaskGroup is a one-scope owner, not a reusable queue; the exact coroutine-closing improvement is version-sensitive. For the library catalogue, add one near-miss that exposes retaining a TaskGroup object as a reusable global scheduler. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers retaining a TaskGroup object as a reusable global scheduler.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Inactive groups reject new work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Inactive groups reject new work?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing retaining a TaskGroup object as a reusable global scheduler be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny science project with sensor coroutines clean up files when one measurement fails. Include one ordinary case, one boundary and one deliberate failure caused by retaining a TaskGroup object as a reusable global scheduler. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: A group that has not entered, has finished, or is shutting down cannot accept another task; current Python also closes a submitted coroutine in this case from 3.13. It shows a trace, not only a final value. The ordinary case should demonstrate “TaskGroup is a one-scope owner, not a reusable queue; the exact coroutine-closing improvement is version-sensitive.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Inactive groups reject new work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Inactive groups reject new work, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 7 OF 20 . Use the core tools

7. Task names and context are diagnostic inputs

Back to contents

create_task forwards supported task options such as name and context, while keyword forwarding evolved across Python releases. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is copying the newest signature into an older deployment without a version test. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Task names and context are diagnostic inputs, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Task names and context are diagnostic inputs chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on copying the newest signature into an older deployment without a version test. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as tg:
    t=tg.create_task(job(),name='catalogue-check')
print(t.get_name())

Explained result. A meaningful name improves inspection, but optional parameters must match the deployed Python documentation. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: family planner. Contrast the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “create_task forwards supported task options such as name and context, while keyword forwarding evolved across Python releases.” Apply this procedure: State the contract for Task names and context are diagnostic inputs, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: A meaningful name improves inspection, but optional parameters must match the deployed Python documentation. For the family planner, add one near-miss that exposes copying the newest signature into an older deployment without a version test. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: library catalogue. Stress-test the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “create_task forwards supported task options such as name and context, while keyword forwarding evolved across Python releases.” Apply this procedure: State the contract for Task names and context are diagnostic inputs, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: A meaningful name improves inspection, but optional parameters must match the deployed Python documentation. For the library catalogue, add one near-miss that exposes copying the newest signature into an older deployment without a version test. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: test laboratory. Explain the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “create_task forwards supported task options such as name and context, while keyword forwarding evolved across Python releases.” Apply this procedure: State the contract for Task names and context are diagnostic inputs, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: A meaningful name improves inspection, but optional parameters must match the deployed Python documentation. For the test laboratory, add one near-miss that exposes copying the newest signature into an older deployment without a version test. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: design decision. Transfer the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “create_task forwards supported task options such as name and context, while keyword forwarding evolved across Python releases.” Apply this procedure: State the contract for Task names and context are diagnostic inputs, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: A meaningful name improves inspection, but optional parameters must match the deployed Python documentation. For the design decision, add one near-miss that exposes copying the newest signature into an older deployment without a version test. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers copying the newest signature into an older deployment without a version test.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Task names and context are diagnostic inputs, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Task names and context are diagnostic inputs?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing copying the newest signature into an older deployment without a version test be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny CCA registration with seat, consent and contact checks must finish within one operation. Include one ordinary case, one boundary and one deliberate failure caused by copying the newest signature into an older deployment without a version test. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: create_task forwards supported task options such as name and context, while keyword forwarding evolved across Python releases. It shows a trace, not only a final value. The ordinary case should demonstrate “A meaningful name improves inspection, but optional parameters must match the deployed Python documentation.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Task names and context are diagnostic inputs, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Task names and context are diagnostic inputs, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 8 OF 20 . Use the core tools

8. First ordinary failure cancels siblings

Back to contents

When a child raises an exception other than CancelledError, the group cancels unfinished siblings and waits for them. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is assuming sibling work continues normally after one child has failed. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for First ordinary failure cancels siblings, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the First ordinary failure cancels siblings chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on assuming sibling work continues normally after one child has failed. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as tg:
    tg.create_task(fails())
    tg.create_task(waiting())

Explained result. The waiting sibling receives cancellation as the group converges on a completed failure state. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: test laboratory. Stress-test the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “When a child raises an exception other than CancelledError, the group cancels unfinished siblings and waits for them.” Apply this procedure: State the contract for First ordinary failure cancels siblings, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The waiting sibling receives cancellation as the group converges on a completed failure state. For the test laboratory, add one near-miss that exposes assuming sibling work continues normally after one child has failed. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: design decision. Explain the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “When a child raises an exception other than CancelledError, the group cancels unfinished siblings and waits for them.” Apply this procedure: State the contract for First ordinary failure cancels siblings, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The waiting sibling receives cancellation as the group converges on a completed failure state. For the design decision, add one near-miss that exposes assuming sibling work continues normally after one child has failed. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: homework dashboard. Transfer the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “When a child raises an exception other than CancelledError, the group cancels unfinished siblings and waits for them.” Apply this procedure: State the contract for First ordinary failure cancels siblings, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The waiting sibling receives cancellation as the group converges on a completed failure state. For the homework dashboard, add one near-miss that exposes assuming sibling work continues normally after one child has failed. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: reading tracker. Predict the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “When a child raises an exception other than CancelledError, the group cancels unfinished siblings and waits for them.” Apply this procedure: State the contract for First ordinary failure cancels siblings, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The waiting sibling receives cancellation as the group converges on a completed failure state. For the reading tracker, add one near-miss that exposes assuming sibling work continues normally after one child has failed. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers assuming sibling work continues normally after one child has failed.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for First ordinary failure cancels siblings, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from First ordinary failure cancels siblings?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing assuming sibling work continues normally after one child has failed be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny family planner with several calendar lookups share one timeout boundary. Include one ordinary case, one boundary and one deliberate failure caused by assuming sibling work continues normally after one child has failed. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: When a child raises an exception other than CancelledError, the group cancels unfinished siblings and waits for them. It shows a trace, not only a final value. The ordinary case should demonstrate “The waiting sibling receives cancellation as the group converges on a completed failure state.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for First ordinary failure cancels siblings, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For First ordinary failure cancels siblings, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 9 OF 20 . Handle boundaries

9. CancelledError is control flow

Back to contents

asyncio cancellation is delivered by raising CancelledError at an await point and normally belongs to cooperative shutdown. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is treating cancellation as an ordinary validation error and suppressing it accidentally. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for CancelledError is control flow, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the CancelledError is control flow chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on treating cancellation as an ordinary validation error and suppressing it accidentally. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

try:
    await resource_work()
finally:
    await close_resource()

Explained result. The finally block performs cleanup; cancellation should normally continue after cleanup rather than vanish. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: homework dashboard. Explain the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio cancellation is delivered by raising CancelledError at an await point and normally belongs to cooperative shutdown.” Apply this procedure: State the contract for CancelledError is control flow, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The finally block performs cleanup; cancellation should normally continue after cleanup rather than vanish. For the homework dashboard, add one near-miss that exposes treating cancellation as an ordinary validation error and suppressing it accidentally. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: reading tracker. Transfer the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio cancellation is delivered by raising CancelledError at an await point and normally belongs to cooperative shutdown.” Apply this procedure: State the contract for CancelledError is control flow, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The finally block performs cleanup; cancellation should normally continue after cleanup rather than vanish. For the reading tracker, add one near-miss that exposes treating cancellation as an ordinary validation error and suppressing it accidentally. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: science project. Predict the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio cancellation is delivered by raising CancelledError at an await point and normally belongs to cooperative shutdown.” Apply this procedure: State the contract for CancelledError is control flow, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The finally block performs cleanup; cancellation should normally continue after cleanup rather than vanish. For the science project, add one near-miss that exposes treating cancellation as an ordinary validation error and suppressing it accidentally. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: CCA registration. Contrast the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio cancellation is delivered by raising CancelledError at an await point and normally belongs to cooperative shutdown.” Apply this procedure: State the contract for CancelledError is control flow, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The finally block performs cleanup; cancellation should normally continue after cleanup rather than vanish. For the CCA registration, add one near-miss that exposes treating cancellation as an ordinary validation error and suppressing it accidentally. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers treating cancellation as an ordinary validation error and suppressing it accidentally.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for CancelledError is control flow, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from CancelledError is control flow?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing treating cancellation as an ordinary validation error and suppressing it accidentally be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny library catalogue with nested groups separate book-level failures from batch-level cancellation. Include one ordinary case, one boundary and one deliberate failure caused by treating cancellation as an ordinary validation error and suppressing it accidentally. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: asyncio cancellation is delivered by raising CancelledError at an await point and normally belongs to cooperative shutdown. It shows a trace, not only a final value. The ordinary case should demonstrate “The finally block performs cleanup; cancellation should normally continue after cleanup rather than vanish.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for CancelledError is control flow, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For CancelledError is control flow, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 10 OF 20 . Handle boundaries

10. Cleanup belongs in try/finally

Back to contents

A cancelled coroutine still needs deterministic cleanup for locks, streams, temporary files and other owned resources. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is placing cleanup only after an await that may never return normally. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Cleanup belongs in try/finally, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Cleanup belongs in try/finally chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on placing cleanup only after an await that may never return normally. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

handle=await open_async()
try:
    await use(handle)
finally:
    await handle.aclose()

Explained result. The owned handle is closed whether use succeeds, fails or is cancelled. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: science project. Transfer the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A cancelled coroutine still needs deterministic cleanup for locks, streams, temporary files and other owned resources.” Apply this procedure: State the contract for Cleanup belongs in try/finally, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The owned handle is closed whether use succeeds, fails or is cancelled. For the science project, add one near-miss that exposes placing cleanup only after an await that may never return normally. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: CCA registration. Predict the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A cancelled coroutine still needs deterministic cleanup for locks, streams, temporary files and other owned resources.” Apply this procedure: State the contract for Cleanup belongs in try/finally, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The owned handle is closed whether use succeeds, fails or is cancelled. For the CCA registration, add one near-miss that exposes placing cleanup only after an await that may never return normally. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: family planner. Contrast the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A cancelled coroutine still needs deterministic cleanup for locks, streams, temporary files and other owned resources.” Apply this procedure: State the contract for Cleanup belongs in try/finally, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The owned handle is closed whether use succeeds, fails or is cancelled. For the family planner, add one near-miss that exposes placing cleanup only after an await that may never return normally. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: library catalogue. Stress-test the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “A cancelled coroutine still needs deterministic cleanup for locks, streams, temporary files and other owned resources.” Apply this procedure: State the contract for Cleanup belongs in try/finally, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The owned handle is closed whether use succeeds, fails or is cancelled. For the library catalogue, add one near-miss that exposes placing cleanup only after an await that may never return normally. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers placing cleanup only after an await that may never return normally.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Cleanup belongs in try/finally, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Cleanup belongs in try/finally?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing placing cleanup only after an await that may never return normally be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny test laboratory with success, failure, cancellation, timeout and nested groups are observed on a disposable loop. Include one ordinary case, one boundary and one deliberate failure caused by placing cleanup only after an await that may never return normally. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: A cancelled coroutine still needs deterministic cleanup for locks, streams, temporary files and other owned resources. It shows a trace, not only a final value. The ordinary case should demonstrate “The owned handle is closed whether use succeeds, fails or is cancelled.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Cleanup belongs in try/finally, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Cleanup belongs in try/finally, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 11 OF 20 . Handle boundaries

11. Do not swallow cancellation casually

Back to contents

Code that catches CancelledError and continues can mislead TaskGroup and timeout machinery that rely on cancellation state. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is writing except BaseException pass around an entire coroutine. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Do not swallow cancellation casually, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Do not swallow cancellation casually chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on writing except BaseException pass around an entire coroutine. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

try:
    await step()
except asyncio.CancelledError:
    await rollback()
    raise

Explained result. Cleanup runs and the cancellation is re-raised so the structured owner sees the true state. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: family planner. Predict the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Code that catches CancelledError and continues can mislead TaskGroup and timeout machinery that rely on cancellation state.” Apply this procedure: State the contract for Do not swallow cancellation casually, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Cleanup runs and the cancellation is re-raised so the structured owner sees the true state. For the family planner, add one near-miss that exposes writing except BaseException pass around an entire coroutine. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: library catalogue. Contrast the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Code that catches CancelledError and continues can mislead TaskGroup and timeout machinery that rely on cancellation state.” Apply this procedure: State the contract for Do not swallow cancellation casually, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Cleanup runs and the cancellation is re-raised so the structured owner sees the true state. For the library catalogue, add one near-miss that exposes writing except BaseException pass around an entire coroutine. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: test laboratory. Stress-test the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Code that catches CancelledError and continues can mislead TaskGroup and timeout machinery that rely on cancellation state.” Apply this procedure: State the contract for Do not swallow cancellation casually, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Cleanup runs and the cancellation is re-raised so the structured owner sees the true state. For the test laboratory, add one near-miss that exposes writing except BaseException pass around an entire coroutine. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: design decision. Explain the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Code that catches CancelledError and continues can mislead TaskGroup and timeout machinery that rely on cancellation state.” Apply this procedure: State the contract for Do not swallow cancellation casually, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Cleanup runs and the cancellation is re-raised so the structured owner sees the true state. For the design decision, add one near-miss that exposes writing except BaseException pass around an entire coroutine. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers writing except BaseException pass around an entire coroutine.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Do not swallow cancellation casually, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Do not swallow cancellation casually?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing writing except BaseException pass around an entire coroutine be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny design decision with TaskGroup is compared with gather, create_task without ownership and a durable job queue. Include one ordinary case, one boundary and one deliberate failure caused by writing except BaseException pass around an entire coroutine. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: Code that catches CancelledError and continues can mislead TaskGroup and timeout machinery that rely on cancellation state. It shows a trace, not only a final value. The ordinary case should demonstrate “Cleanup runs and the cancellation is re-raised so the structured owner sees the true state.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Do not swallow cancellation casually, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Do not swallow cancellation casually, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 12 OF 20 . Handle boundaries

12. Failures are grouped

Back to contents

After sibling shutdown, non-cancellation failures are combined in an ExceptionGroup or BaseExceptionGroup. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is expecting only the first visible exception and losing other concurrent evidence. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Failures are grouped, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Failures are grouped chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on expecting only the first visible exception and losing other concurrent evidence. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

try:
    async with asyncio.TaskGroup() as tg:
        tg.create_task(bad_a()); tg.create_task(bad_b())
except* ValueError as eg:
    print(len(eg.exceptions))

Explained result. except* can select matching leaves while preserving the grouped nature of concurrent failure. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: test laboratory. Contrast the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “After sibling shutdown, non-cancellation failures are combined in an ExceptionGroup or BaseExceptionGroup.” Apply this procedure: State the contract for Failures are grouped, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: except* can select matching leaves while preserving the grouped nature of concurrent failure. For the test laboratory, add one near-miss that exposes expecting only the first visible exception and losing other concurrent evidence. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: design decision. Stress-test the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “After sibling shutdown, non-cancellation failures are combined in an ExceptionGroup or BaseExceptionGroup.” Apply this procedure: State the contract for Failures are grouped, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: except* can select matching leaves while preserving the grouped nature of concurrent failure. For the design decision, add one near-miss that exposes expecting only the first visible exception and losing other concurrent evidence. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: homework dashboard. Explain the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “After sibling shutdown, non-cancellation failures are combined in an ExceptionGroup or BaseExceptionGroup.” Apply this procedure: State the contract for Failures are grouped, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: except* can select matching leaves while preserving the grouped nature of concurrent failure. For the homework dashboard, add one near-miss that exposes expecting only the first visible exception and losing other concurrent evidence. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: reading tracker. Transfer the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “After sibling shutdown, non-cancellation failures are combined in an ExceptionGroup or BaseExceptionGroup.” Apply this procedure: State the contract for Failures are grouped, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: except* can select matching leaves while preserving the grouped nature of concurrent failure. For the reading tracker, add one near-miss that exposes expecting only the first visible exception and losing other concurrent evidence. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers expecting only the first visible exception and losing other concurrent evidence.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Failures are grouped, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Failures are grouped?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing expecting only the first visible exception and losing other concurrent evidence be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny homework dashboard with three independent subject summaries are fetched under one visible request. Include one ordinary case, one boundary and one deliberate failure caused by expecting only the first visible exception and losing other concurrent evidence. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: After sibling shutdown, non-cancellation failures are combined in an ExceptionGroup or BaseExceptionGroup. It shows a trace, not only a final value. The ordinary case should demonstrate “except* can select matching leaves while preserving the grouped nature of concurrent failure.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Failures are grouped, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Failures are grouped, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 13 OF 20 . Debug and verify

13. except star handles matching leaves

Back to contents

The except* syntax splits an exception group by type rather than behaving like an ordinary except over one scalar exception. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is flattening every failure into an untyped message string. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for except star handles matching leaves, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the except star handles matching leaves chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on flattening every failure into an untyped message string. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

except* OSError as group:
    for error in group.exceptions: log(error)

Explained result. Matching OSError leaves can be handled without pretending unrelated failures have the same recovery. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: homework dashboard. Stress-test the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “The except* syntax splits an exception group by type rather than behaving like an ordinary except over one scalar exception.” Apply this procedure: State the contract for except star handles matching leaves, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Matching OSError leaves can be handled without pretending unrelated failures have the same recovery. For the homework dashboard, add one near-miss that exposes flattening every failure into an untyped message string. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: reading tracker. Explain the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “The except* syntax splits an exception group by type rather than behaving like an ordinary except over one scalar exception.” Apply this procedure: State the contract for except star handles matching leaves, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Matching OSError leaves can be handled without pretending unrelated failures have the same recovery. For the reading tracker, add one near-miss that exposes flattening every failure into an untyped message string. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: science project. Transfer the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “The except* syntax splits an exception group by type rather than behaving like an ordinary except over one scalar exception.” Apply this procedure: State the contract for except star handles matching leaves, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Matching OSError leaves can be handled without pretending unrelated failures have the same recovery. For the science project, add one near-miss that exposes flattening every failure into an untyped message string. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: CCA registration. Predict the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “The except* syntax splits an exception group by type rather than behaving like an ordinary except over one scalar exception.” Apply this procedure: State the contract for except star handles matching leaves, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Matching OSError leaves can be handled without pretending unrelated failures have the same recovery. For the CCA registration, add one near-miss that exposes flattening every failure into an untyped message string. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers flattening every failure into an untyped message string.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for except star handles matching leaves, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from except star handles matching leaves?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing flattening every failure into an untyped message string be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny reading tracker with several book records are checked and one invalid record stops sibling work. Include one ordinary case, one boundary and one deliberate failure caused by flattening every failure into an untyped message string. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: The except* syntax splits an exception group by type rather than behaving like an ordinary except over one scalar exception. It shows a trace, not only a final value. The ordinary case should demonstrate “Matching OSError leaves can be handled without pretending unrelated failures have the same recovery.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for except star handles matching leaves, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For except star handles matching leaves, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 14 OF 20 . Debug and verify

14. KeyboardInterrupt and SystemExit are special

Back to contents

TaskGroup cancels and waits for children, then re-raises KeyboardInterrupt or SystemExit instead of wrapping it as an ordinary group. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is catching BaseException broadly and converting process-control signals into application errors. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for KeyboardInterrupt and SystemExit are special, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the KeyboardInterrupt and SystemExit are special chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on catching BaseException broadly and converting process-control signals into application errors. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as tg:
    tg.create_task(run())

Explained result. The surrounding application should preserve the documented special propagation of these base exceptions. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: science project. Explain the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup cancels and waits for children, then re-raises KeyboardInterrupt or SystemExit instead of wrapping it as an ordinary group.” Apply this procedure: State the contract for KeyboardInterrupt and SystemExit are special, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The surrounding application should preserve the documented special propagation of these base exceptions. For the science project, add one near-miss that exposes catching BaseException broadly and converting process-control signals into application errors. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: CCA registration. Transfer the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup cancels and waits for children, then re-raises KeyboardInterrupt or SystemExit instead of wrapping it as an ordinary group.” Apply this procedure: State the contract for KeyboardInterrupt and SystemExit are special, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The surrounding application should preserve the documented special propagation of these base exceptions. For the CCA registration, add one near-miss that exposes catching BaseException broadly and converting process-control signals into application errors. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: family planner. Predict the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup cancels and waits for children, then re-raises KeyboardInterrupt or SystemExit instead of wrapping it as an ordinary group.” Apply this procedure: State the contract for KeyboardInterrupt and SystemExit are special, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The surrounding application should preserve the documented special propagation of these base exceptions. For the family planner, add one near-miss that exposes catching BaseException broadly and converting process-control signals into application errors. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: library catalogue. Contrast the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup cancels and waits for children, then re-raises KeyboardInterrupt or SystemExit instead of wrapping it as an ordinary group.” Apply this procedure: State the contract for KeyboardInterrupt and SystemExit are special, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The surrounding application should preserve the documented special propagation of these base exceptions. For the library catalogue, add one near-miss that exposes catching BaseException broadly and converting process-control signals into application errors. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers catching BaseException broadly and converting process-control signals into application errors.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for KeyboardInterrupt and SystemExit are special, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from KeyboardInterrupt and SystemExit are special?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing catching BaseException broadly and converting process-control signals into application errors be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny science project with sensor coroutines clean up files when one measurement fails. Include one ordinary case, one boundary and one deliberate failure caused by catching BaseException broadly and converting process-control signals into application errors. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: TaskGroup cancels and waits for children, then re-raises KeyboardInterrupt or SystemExit instead of wrapping it as an ordinary group. It shows a trace, not only a final value. The ordinary case should demonstrate “The surrounding application should preserve the documented special propagation of these base exceptions.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for KeyboardInterrupt and SystemExit are special, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For KeyboardInterrupt and SystemExit are special, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 15 OF 20 . Debug and verify

15. A body failure joins the group protocol

Back to contents

If the async with body itself raises while children exist, remaining children are cancelled and the body exception participates in the resulting group unless specially re-raised. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is analysing only child functions and ignoring code inside the owning block. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for A body failure joins the group protocol, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the A body failure joins the group protocol chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on analysing only child functions and ignoring code inside the owning block. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as tg:
    tg.create_task(worker())
    raise ValueError('body failed')

Explained result. The owner block is part of the structured failure boundary, not an observer outside it. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: family planner. Transfer the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “If the async with body itself raises while children exist, remaining children are cancelled and the body exception participates in the resulting group unless specially re-raised.” Apply this procedure: State the contract for A body failure joins the group protocol, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The owner block is part of the structured failure boundary, not an observer outside it. For the family planner, add one near-miss that exposes analysing only child functions and ignoring code inside the owning block. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: library catalogue. Predict the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “If the async with body itself raises while children exist, remaining children are cancelled and the body exception participates in the resulting group unless specially re-raised.” Apply this procedure: State the contract for A body failure joins the group protocol, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The owner block is part of the structured failure boundary, not an observer outside it. For the library catalogue, add one near-miss that exposes analysing only child functions and ignoring code inside the owning block. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: test laboratory. Contrast the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “If the async with body itself raises while children exist, remaining children are cancelled and the body exception participates in the resulting group unless specially re-raised.” Apply this procedure: State the contract for A body failure joins the group protocol, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The owner block is part of the structured failure boundary, not an observer outside it. For the test laboratory, add one near-miss that exposes analysing only child functions and ignoring code inside the owning block. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: design decision. Stress-test the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “If the async with body itself raises while children exist, remaining children are cancelled and the body exception participates in the resulting group unless specially re-raised.” Apply this procedure: State the contract for A body failure joins the group protocol, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The owner block is part of the structured failure boundary, not an observer outside it. For the design decision, add one near-miss that exposes analysing only child functions and ignoring code inside the owning block. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers analysing only child functions and ignoring code inside the owning block.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for A body failure joins the group protocol, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from A body failure joins the group protocol?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing analysing only child functions and ignoring code inside the owning block be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny CCA registration with seat, consent and contact checks must finish within one operation. Include one ordinary case, one boundary and one deliberate failure caused by analysing only child functions and ignoring code inside the owning block. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: If the async with body itself raises while children exist, remaining children are cancelled and the body exception participates in the resulting group unless specially re-raised. It shows a trace, not only a final value. The ordinary case should demonstrate “The owner block is part of the structured failure boundary, not an observer outside it.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for A body failure joins the group protocol, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For A body failure joins the group protocol, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 16 OF 20 . Debug and verify

16. Nested groups preserve failure structure

Back to contents

Inner and outer groups process their own child failures while Python preserves cancellation counts and separates internal wake-up cancellation from external cancellation. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is assuming simultaneous nested failures collapse into an arbitrary single exception. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Nested groups preserve failure structure, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Nested groups preserve failure structure chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on assuming simultaneous nested failures collapse into an arbitrary single exception. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as outer:
    outer.create_task(inner_group())
    outer.create_task(other())

Explained result. Each lexical owner finishes its shutdown protocol, allowing nested ExceptionGroup structure to retain meaning. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: test laboratory. Predict the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Inner and outer groups process their own child failures while Python preserves cancellation counts and separates internal wake-up cancellation from external cancellation.” Apply this procedure: State the contract for Nested groups preserve failure structure, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Each lexical owner finishes its shutdown protocol, allowing nested ExceptionGroup structure to retain meaning. For the test laboratory, add one near-miss that exposes assuming simultaneous nested failures collapse into an arbitrary single exception. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: design decision. Contrast the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Inner and outer groups process their own child failures while Python preserves cancellation counts and separates internal wake-up cancellation from external cancellation.” Apply this procedure: State the contract for Nested groups preserve failure structure, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Each lexical owner finishes its shutdown protocol, allowing nested ExceptionGroup structure to retain meaning. For the design decision, add one near-miss that exposes assuming simultaneous nested failures collapse into an arbitrary single exception. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: homework dashboard. Stress-test the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Inner and outer groups process their own child failures while Python preserves cancellation counts and separates internal wake-up cancellation from external cancellation.” Apply this procedure: State the contract for Nested groups preserve failure structure, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Each lexical owner finishes its shutdown protocol, allowing nested ExceptionGroup structure to retain meaning. For the homework dashboard, add one near-miss that exposes assuming simultaneous nested failures collapse into an arbitrary single exception. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: reading tracker. Explain the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Inner and outer groups process their own child failures while Python preserves cancellation counts and separates internal wake-up cancellation from external cancellation.” Apply this procedure: State the contract for Nested groups preserve failure structure, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Each lexical owner finishes its shutdown protocol, allowing nested ExceptionGroup structure to retain meaning. For the reading tracker, add one near-miss that exposes assuming simultaneous nested failures collapse into an arbitrary single exception. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers assuming simultaneous nested failures collapse into an arbitrary single exception.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Nested groups preserve failure structure, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Nested groups preserve failure structure?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing assuming simultaneous nested failures collapse into an arbitrary single exception be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny family planner with several calendar lookups share one timeout boundary. Include one ordinary case, one boundary and one deliberate failure caused by assuming simultaneous nested failures collapse into an arbitrary single exception. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: Inner and outer groups process their own child failures while Python preserves cancellation counts and separates internal wake-up cancellation from external cancellation. It shows a trace, not only a final value. The ordinary case should demonstrate “Each lexical owner finishes its shutdown protocol, allowing nested ExceptionGroup structure to retain meaning.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Nested groups preserve failure structure, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Nested groups preserve failure structure, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 17 OF 20 . Transfer with judgment

17. External cancellation remains visible

Back to contents

Cancellation requested by a caller must not be lost merely because a group is also collecting an internal failure. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is turning a caller timeout into only a child-error report. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for External cancellation remains visible, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the External cancellation remains visible chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on turning a caller timeout into only a child-error report. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

task=asyncio.create_task(run_group())
task.cancel()

Explained result. The enclosing task retains cancellation semantics while the group safely settles its children. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: homework dashboard. Contrast the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Cancellation requested by a caller must not be lost merely because a group is also collecting an internal failure.” Apply this procedure: State the contract for External cancellation remains visible, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The enclosing task retains cancellation semantics while the group safely settles its children. For the homework dashboard, add one near-miss that exposes turning a caller timeout into only a child-error report. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: reading tracker. Stress-test the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Cancellation requested by a caller must not be lost merely because a group is also collecting an internal failure.” Apply this procedure: State the contract for External cancellation remains visible, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The enclosing task retains cancellation semantics while the group safely settles its children. For the reading tracker, add one near-miss that exposes turning a caller timeout into only a child-error report. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: science project. Explain the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Cancellation requested by a caller must not be lost merely because a group is also collecting an internal failure.” Apply this procedure: State the contract for External cancellation remains visible, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The enclosing task retains cancellation semantics while the group safely settles its children. For the science project, add one near-miss that exposes turning a caller timeout into only a child-error report. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: CCA registration. Transfer the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “Cancellation requested by a caller must not be lost merely because a group is also collecting an internal failure.” Apply this procedure: State the contract for External cancellation remains visible, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The enclosing task retains cancellation semantics while the group safely settles its children. For the CCA registration, add one near-miss that exposes turning a caller timeout into only a child-error report. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers turning a caller timeout into only a child-error report.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for External cancellation remains visible, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from External cancellation remains visible?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing turning a caller timeout into only a child-error report be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny library catalogue with nested groups separate book-level failures from batch-level cancellation. Include one ordinary case, one boundary and one deliberate failure caused by turning a caller timeout into only a child-error report. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: Cancellation requested by a caller must not be lost merely because a group is also collecting an internal failure. It shows a trace, not only a final value. The ordinary case should demonstrate “The enclosing task retains cancellation semantics while the group safely settles its children.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for External cancellation remains visible, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For External cancellation remains visible, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 18 OF 20 . Transfer with judgment

18. TaskGroup differs from gather

Back to contents

TaskGroup cancels remaining siblings after an ordinary child failure, whereas gather has different propagation choices and does not provide the same lexical ownership guarantee. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is calling the two APIs interchangeable because both can await several coroutines. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for TaskGroup differs from gather, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the TaskGroup differs from gather chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on calling the two APIs interchangeable because both can await several coroutines. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.TaskGroup() as tg:
    tasks=[tg.create_task(f()) for f in funcs]

Explained result. Choose from the required failure and ownership contract, not from superficial brevity. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: science project. Stress-test the rule using sensor coroutines clean up files when one measurement fails. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup cancels remaining siblings after an ordinary child failure, whereas gather has different propagation choices and does not provide the same lexical ownership guarantee.” Apply this procedure: State the contract for TaskGroup differs from gather, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Choose from the required failure and ownership contract, not from superficial brevity. For the science project, add one near-miss that exposes calling the two APIs interchangeable because both can await several coroutines. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: CCA registration. Explain the rule using seat, consent and contact checks must finish within one operation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup cancels remaining siblings after an ordinary child failure, whereas gather has different propagation choices and does not provide the same lexical ownership guarantee.” Apply this procedure: State the contract for TaskGroup differs from gather, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Choose from the required failure and ownership contract, not from superficial brevity. For the CCA registration, add one near-miss that exposes calling the two APIs interchangeable because both can await several coroutines. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: family planner. Transfer the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup cancels remaining siblings after an ordinary child failure, whereas gather has different propagation choices and does not provide the same lexical ownership guarantee.” Apply this procedure: State the contract for TaskGroup differs from gather, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Choose from the required failure and ownership contract, not from superficial brevity. For the family planner, add one near-miss that exposes calling the two APIs interchangeable because both can await several coroutines. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: library catalogue. Predict the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup cancels remaining siblings after an ordinary child failure, whereas gather has different propagation choices and does not provide the same lexical ownership guarantee.” Apply this procedure: State the contract for TaskGroup differs from gather, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Choose from the required failure and ownership contract, not from superficial brevity. For the library catalogue, add one near-miss that exposes calling the two APIs interchangeable because both can await several coroutines. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers calling the two APIs interchangeable because both can await several coroutines.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for TaskGroup differs from gather, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from TaskGroup differs from gather?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing calling the two APIs interchangeable because both can await several coroutines be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny test laboratory with success, failure, cancellation, timeout and nested groups are observed on a disposable loop. Include one ordinary case, one boundary and one deliberate failure caused by calling the two APIs interchangeable because both can await several coroutines. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: TaskGroup cancels remaining siblings after an ordinary child failure, whereas gather has different propagation choices and does not provide the same lexical ownership guarantee. It shows a trace, not only a final value. The ordinary case should demonstrate “Choose from the required failure and ownership contract, not from superficial brevity.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for TaskGroup differs from gather, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For TaskGroup differs from gather, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 19 OF 20 . Transfer with judgment

19. Timeouts should wrap the owned operation

Back to contents

asyncio.timeout can bound a group so the caller has one clear deadline and children participate in cancellation-safe cleanup. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is adding unrelated per-task timers without deciding which deadline owns the operation. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Timeouts should wrap the owned operation, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Timeouts should wrap the owned operation chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on adding unrelated per-task timers without deciding which deadline owns the operation. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

async with asyncio.timeout(2):
    async with asyncio.TaskGroup() as tg:
        tg.create_task(load())

Explained result. The enclosing timeout bounds the structured operation and the group settles its children before control escapes. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: family planner. Explain the rule using several calendar lookups share one timeout boundary. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio.timeout can bound a group so the caller has one clear deadline and children participate in cancellation-safe cleanup.” Apply this procedure: State the contract for Timeouts should wrap the owned operation, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The enclosing timeout bounds the structured operation and the group settles its children before control escapes. For the family planner, add one near-miss that exposes adding unrelated per-task timers without deciding which deadline owns the operation. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: library catalogue. Transfer the rule using nested groups separate book-level failures from batch-level cancellation. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio.timeout can bound a group so the caller has one clear deadline and children participate in cancellation-safe cleanup.” Apply this procedure: State the contract for Timeouts should wrap the owned operation, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The enclosing timeout bounds the structured operation and the group settles its children before control escapes. For the library catalogue, add one near-miss that exposes adding unrelated per-task timers without deciding which deadline owns the operation. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: test laboratory. Predict the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio.timeout can bound a group so the caller has one clear deadline and children participate in cancellation-safe cleanup.” Apply this procedure: State the contract for Timeouts should wrap the owned operation, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The enclosing timeout bounds the structured operation and the group settles its children before control escapes. For the test laboratory, add one near-miss that exposes adding unrelated per-task timers without deciding which deadline owns the operation. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: design decision. Contrast the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “asyncio.timeout can bound a group so the caller has one clear deadline and children participate in cancellation-safe cleanup.” Apply this procedure: State the contract for Timeouts should wrap the owned operation, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The enclosing timeout bounds the structured operation and the group settles its children before control escapes. For the design decision, add one near-miss that exposes adding unrelated per-task timers without deciding which deadline owns the operation. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers adding unrelated per-task timers without deciding which deadline owns the operation.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Timeouts should wrap the owned operation, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Timeouts should wrap the owned operation?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing adding unrelated per-task timers without deciding which deadline owns the operation be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny design decision with TaskGroup is compared with gather, create_task without ownership and a durable job queue. Include one ordinary case, one boundary and one deliberate failure caused by adding unrelated per-task timers without deciding which deadline owns the operation. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: asyncio.timeout can bound a group so the caller has one clear deadline and children participate in cancellation-safe cleanup. It shows a trace, not only a final value. The ordinary case should demonstrate “The enclosing timeout bounds the structured operation and the group settles its children before control escapes.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Timeouts should wrap the owned operation, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Timeouts should wrap the owned operation, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

CHAPTER 20 OF 20 . Transfer with judgment

20. Version-aware cancellation and final choice

Back to contents

TaskGroup.cancel is a Python 3.15 addition; earlier versions use other documented patterns, and TaskGroup itself is for bounded child work rather than durable background jobs. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.

The high-value mistake in this chapter is teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Version-aware cancellation and final choice, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Version-aware cancellation and final choice chapter on Python asyncio.TaskGroup, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

if hasattr(tg,'cancel'):
    tg.cancel()

Explained result. Check the runtime first; choose TaskGroup when one scope owns child completion, and choose a durable queue or service when work must outlive that scope. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.

Four purposeful transfer cases

Case 1: test laboratory. Transfer the rule using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup.cancel is a Python 3.15 addition; earlier versions use other documented patterns, and TaskGroup itself is for bounded child work rather than durable background jobs.” Apply this procedure: State the contract for Version-aware cancellation and final choice, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Check the runtime first; choose TaskGroup when one scope owns child completion, and choose a durable queue or service when work must outlive that scope. For the test laboratory, add one near-miss that exposes teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 2: design decision. Predict the rule using TaskGroup is compared with gather, create_task without ownership and a durable job queue. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup.cancel is a Python 3.15 addition; earlier versions use other documented patterns, and TaskGroup itself is for bounded child work rather than durable background jobs.” Apply this procedure: State the contract for Version-aware cancellation and final choice, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Check the runtime first; choose TaskGroup when one scope owns child completion, and choose a durable queue or service when work must outlive that scope. For the design decision, add one near-miss that exposes teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 3: homework dashboard. Contrast the rule using three independent subject summaries are fetched under one visible request. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup.cancel is a Python 3.15 addition; earlier versions use other documented patterns, and TaskGroup itself is for bounded child work rather than durable background jobs.” Apply this procedure: State the contract for Version-aware cancellation and final choice, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Check the runtime first; choose TaskGroup when one scope owns child completion, and choose a durable queue or service when work must outlive that scope. For the homework dashboard, add one near-miss that exposes teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Case 4: reading tracker. Stress-test the rule using several book records are checked and one invalid record stops sibling work. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.

Reasoned route. Begin with “TaskGroup.cancel is a Python 3.15 addition; earlier versions use other documented patterns, and TaskGroup itself is for bounded child work rather than durable background jobs.” Apply this procedure: State the contract for Version-aware cancellation and final choice, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Check the runtime first; choose TaskGroup when one scope owns child completion, and choose a durable queue or service when work must outlive that scope. For the reading tracker, add one near-miss that exposes teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.

Diagnostic route

  • Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
  • Boundary check: create the smallest input that triggers teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Version-aware cancellation and final choice, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” and record the first changed observation.
  • Transfer check: repeat the rule in a second context and identify what remains invariant.

A parent does not need to know the final Python asyncio.TaskGroup syntax. For this chapter, useful prompts are: “What did you expect from Version-aware cancellation and final choice?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny homework dashboard with three independent subject summaries are fetched under one visible request. Include one ordinary case, one boundary and one deliberate failure caused by teaching a 3.15 convenience as if it existed in every 3.11-plus interpreter. Predict each result before using a tool, then report the first point where observation differs from prediction.

Answer guide. A strong response starts with the rule: TaskGroup.cancel is a Python 3.15 addition; earlier versions use other documented patterns, and TaskGroup itself is for bounded child work rather than durable background jobs. It shows a trace, not only a final value. The ordinary case should demonstrate “Check the runtime first; choose TaskGroup when one scope owns child completion, and choose a durable queue or service when work must outlive that scope.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Version-aware cancellation and final choice, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Version-aware cancellation and final choice, separate the documented Python asyncio.TaskGroup mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.

Previous chapter . Contents . Next chapter

Parent guide: choose the next useful step

Start with evidence, not a label such as careless. Ask for one prediction and one trace. If the first transition is wrong, rebuild the model. If the model is sound but syntax fails, practise reference use. If routine cases are correct but boundaries fail, vary ties, defaults, unsupported inputs, ownership or missing paths. If explanations transfer, move to a small project.

Keep a weekly record with four lines: concept, prediction, observed difference and next test. Stop when fatigue replaces reasoning. A smaller case tomorrow is more useful than another hour of copying tonight.

Seek specialist help when cause and effect remain invisible after examples are reduced, when accessibility or data-loss implications are unclear, or when an important repository, database or application state may be at risk. Good support should make the learner’s reasoning more independent.

Capstone practice with explained routes

1. homework dashboard: model, boundary and recovery

Create a small homework dashboard using three independent subject summaries are fetched under one visible request. Combine “TaskGroup owns a lexical task lifetime” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: An async with block establishes a scope in which child tasks are created and completed before control leaves. Apply: State the contract for TaskGroup owns a lexical task lifetime, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The print runs only after the child has finished or the group has completed its failure protocol. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.

2. reading tracker: model, boundary and recovery

Create a small reading tracker using several book records are checked and one invalid record stops sibling work. Combine “Context exit waits implicitly” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: No separate gather call is required merely to wait for all tasks created in the active group. Apply: State the contract for Context exit waits implicitly, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: Leaving the block is the documented join point for every child accepted by the group. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.

3. science project: model, boundary and recovery

Create a small science project using sensor coroutines clean up files when one measurement fails. Combine “Task names and context are diagnostic inputs” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: create_task forwards supported task options such as name and context, while keyword forwarding evolved across Python releases. Apply: State the contract for Task names and context are diagnostic inputs, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: A meaningful name improves inspection, but optional parameters must match the deployed Python documentation. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.

4. CCA registration: model, boundary and recovery

Create a small CCA registration using seat, consent and contact checks must finish within one operation. Combine “Cleanup belongs in try/finally” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: A cancelled coroutine still needs deterministic cleanup for locks, streams, temporary files and other owned resources. Apply: State the contract for Cleanup belongs in try/finally, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The owned handle is closed whether use succeeds, fails or is cancelled. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.

5. family planner: model, boundary and recovery

Create a small family planner using several calendar lookups share one timeout boundary. Combine “except star handles matching leaves” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: The except* syntax splits an exception group by type rather than behaving like an ordinary except over one scalar exception. Apply: State the contract for except star handles matching leaves, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: Matching OSError leaves can be handled without pretending unrelated failures have the same recovery. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.

6. library catalogue: model, boundary and recovery

Create a small library catalogue using nested groups separate book-level failures from batch-level cancellation. Combine “Nested groups preserve failure structure” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: Inner and outer groups process their own child failures while Python preserves cancellation counts and separates internal wake-up cancellation from external cancellation. Apply: State the contract for Nested groups preserve failure structure, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: Each lexical owner finishes its shutdown protocol, allowing nested ExceptionGroup structure to retain meaning. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.

7. test laboratory: model, boundary and recovery

Create a small test laboratory using success, failure, cancellation, timeout and nested groups are observed on a disposable loop. Combine “Timeouts should wrap the owned operation” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: asyncio.timeout can bound a group so the caller has one clear deadline and children participate in cancellation-safe cleanup. Apply: State the contract for Timeouts should wrap the owned operation, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The enclosing timeout bounds the structured operation and the group settles its children before control escapes. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.

8. design decision: model, boundary and recovery

Create a small design decision using TaskGroup is compared with gather, create_task without ownership and a durable job queue. Combine “Python 3.11 is the availability boundary” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: asyncio.TaskGroup entered the standard library in Python 3.11, so older deployments need a different design or explicit compatibility layer. Apply: State the contract for Python 3.11 is the availability boundary, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The local version and attribute check expose the deployment boundary before code is released. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.

Frequently asked questions

How long should a practice session be?

Use one complete prediction–observation–explanation cycle while attention remains good. Ten to twenty focused minutes can be enough.

Should every option or function be memorised?

No. Memorise the governing distinctions and practise retrieving the official reference. Understanding means predicting and explaining, not reciting a parameter list.

What if the result is correct but the explanation is weak?

Treat it as partial success. Ask for a trace and change one boundary. A reliable model survives controlled variation.

Is the shortest solution the best?

Not automatically. Prefer the solution whose semantics, failure modes and maintenance cost are easiest to justify for the actual project.

When should official documentation be used?

Use it whenever syntax, supported types, SQL dialect behaviour or Git version details matter. Primary documentation settles the current contract.

How can a parent help without technical expertise?

Ask what was predicted, where the first difference appeared, what evidence matters and which smaller example could isolate it.

How do we test transfer?

Change the context, vocabulary and one boundary. Require the learner to identify the invariant before using a tool.

What should be saved after practice?

Keep the corrected rule, one trace, one boundary case and the next question. Avoid storing pages of unexplained output.

Can these exercises replace backups?

No. Use disposable examples and proper backups. Learning should not endanger schoolwork, repositories or personal data.

What counts as mastery?

The learner can predict, verify, diagnose, recover and justify a choice across more than one context, while knowing when to consult the current reference.

Official and supporting references

Return to contents

Continue from here: Start Here · Tuition · Education · Pathways · Parenting 101 · All Site Routes

eduKate Punggol

Contact

83 Punggol Central, Singapore 828761

edu|Kate Bukit Timah

8 Fourth Avenue, Singapore 268674

By Appointment +65 8823 1234
admin@edukatesg.com

Email Us

When a child finally understands, school becomes less frightening and the future opens wider. Email us for the latest schedules and fees.

← 返回

感谢您的回复。 ✨

了解 eduKate Punggol 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读