File size: 3,277 Bytes
406662d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
from typing import ClassVar
DEFAULT_TIMEOUT: int = 30
"""Default timeout for the task."""
_MAX_RETRIES: int = 3 # private constant (note the underscore)
"""Maximum number of retries for the task."""
def run_task(task_name: str):
"""Run a task by name.
Args:
task_name: The name of the task to run.
"""
print(f"Running task: {task_name}")
class TaskRunner:
"""Runs and manages tasks."""
DEFAULT_NAME: ClassVar[str] = "runner"
"""Default name for the runner."""
_registry: ClassVar[dict] = {}
"""Registry of runners."""
def __init__(self, name: str):
"""Initialize the runner.
Args:
name: The name of the runner.
"""
self.name = name
self._tasks = [] # private instance variable
def __del__(self):
"""Clean up the runner."""
print(f"Cleaning up {self.name}")
def __repr__(self) -> str:
return f"TaskRunner(name={self.name!r})"
def __str__(self) -> str:
return f"TaskRunner: {self.name}"
"""
Properties.
"""
@property
def task_count(self) -> int:
return len(self._tasks)
"""
Operations.
"""
def initialize(self):
"""Initialize the runner."""
print("Initializing runner...")
def update(self, task: str):
"""Update the runner with a new task.
Args:
task: The task to add.
"""
self._tasks.append(task)
print(f"Added task: {task}")
def close(self):
"""Close the runner."""
print("Closing runner...")
"""
Operations: Registration.
"""
@classmethod
def register(cls, name: str, runner: "TaskRunner"):
"""Register a runner.
Args:
name: The name of the runner.
runner: The runner to register.
"""
if name in cls._registry:
_log_error(f"Runner {name} already registered. Skipping registration.")
return
cls._registry[name] = runner
@staticmethod
def validate_task(task: str) -> bool:
"""Validate a task.
Args:
task: The task to validate.
Returns:
True if the task is valid, False otherwise.
"""
return bool(task and task.strip())
"""
Internal operations.
"""
def _reset(self):
"""Reset the runner."""
self._tasks.clear()
@classmethod
def _get_registry(cls) -> dict:
"""Get the registry."""
return cls._registry
@staticmethod
def _internal_helper():
"""Internal helper."""
print("Internal helper called.")
"""
Helper operations.
"""
def _log_error(message: str):
"""Internal helper to log errors.
Args:
message: The message to log.
"""
print(f"[ERROR] {message}")
class _TaskHelper:
"""Private utility class for internal task logic."""
def compute(self) -> int:
"""Compute the result.
Returns:
The result of the computation.
"""
return 42
|