Skip to content

Commit

Permalink
SQ: Bulkheads: Protect RootTask
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfstr committed Feb 3, 2024
1 parent 57c0fba commit 1b3ea99
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/crystal/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,13 +1585,19 @@ def try_get_next_task_unit(self):

return super().try_get_next_task_unit()

# === Events ===

@capture_crashes_to(task)
def child_task_did_complete(self, task: Task) -> None:
task.dispose()

@capture_crashes_to(self)
def did_schedule_all_children(self) -> None:
# Remove completed children after each scheduling pass
self.clear_completed_children()

# === Protected Operations: Finish & Cleanup ===

@overrides
def clear_children_if_all_complete(self) -> bool:
raise NotImplementedError(
Expand All @@ -1607,13 +1613,17 @@ def fg_task() -> None:
# NOTE: Must synchronize access to RootTask.children with foreground thread
fg_call_and_wait(fg_task)

# === Public Operations ===

def interrupt(self) -> None:
"""
Stop all descendent tasks, asynchronously,
by interrupting the scheduler thread.
"""
self.finish()

# === Utility ===

def __repr__(self) -> str:
return f'<RootTask at 0x{id(self):x}>'

Expand Down

0 comments on commit 1b3ea99

Please sign in to comment.