async def self_cancel(*, task_status: TaskStatus) -> None: nonlocal done task_status.started() with move_on_after(-1): await Event().wait() done = True
async def taskfunc(*, task_status: TaskStatus) -> None: task_status.started() with pytest.raises( RuntimeError, match="called 'started' twice on the same task status"): task_status.started()
async def _track_feedback( self, subscription: abc.Subscription[abc.ActionFeedback[abc.FeedbackT]], *, task_status: TaskStatus = anyio.TASK_STATUS_IGNORED, ) -> None: async with subscription, self._feedback_send_stream: task_status.started() async for msg in subscription: if msg.status.goal_id.id == self._goal_id.id: await self._feedback_send_stream.send(msg.feedback)
async def manage_time( self, *, task_status: TaskStatus = anyio.TASK_STATUS_IGNORED ) -> None: use_sim_time = await self.get_param_default("/use_sim_time", False) if not use_sim_time: task_status.started() else: self._time = Time(0, 0) task_status.started() async with self.create_subscription("/clock", Clock) as subscription: async for clock in subscription: self._time = clock.clock
async def task(task_status: TaskStatus) -> NoReturn: nonlocal completed with CancelScope() as scope: # Enable the shield a little after the scope starts to make this test # general, even though it has no bearing on the current implementation. await sleep(0.1) scope.shield = True task_status.started() await sleep(0.1) completed = True scope.shield = False await sleep(1) pytest.fail("Execution should not reach this point")
async def _signal_handler( ros_node: Node, *, task_status: TaskStatus = anyio.TASK_STATUS_IGNORED ) -> None: async with anyio.open_signal_receiver(signal.SIGINT, signal.SIGTERM) as signals: task_status.started() async for signum in signals: if signum == signal.SIGINT: print("Ctrl+C pressed!") else: print("Terminated!") ros_node.signal_shutdown() return
async def _track_status( self, subscription: abc.Subscription[GoalStatusArray], *, task_status: TaskStatus = anyio.TASK_STATUS_IGNORED, ) -> None: async with subscription: task_status.started() async for msg in subscription: self._sm.update_status(msg) if self._sm.comm_state.is_terminal: self._terminated.set() break
async def _track_result( self, subscription: abc.Subscription[abc.ActionResult[abc.ResultT]], *, task_status: TaskStatus = anyio.TASK_STATUS_IGNORED, ) -> None: async with subscription: task_status.started() async for msg in subscription: if (msg.status.goal_id.id == self._goal_id.id and self._sm.update_on_result_status(msg.status)): self._result = msg.result self._terminated.set() break
async def track( self, sub_status: abc.Subscription[GoalStatusArray], sub_feedback: abc.Subscription[abc.ActionFeedback[abc.FeedbackT]], sub_result: abc.Subscription[abc.ActionResult[abc.ResultT]], *, task_status: TaskStatus = anyio.TASK_STATUS_IGNORED, ) -> None: async with anyio.create_task_group() as task_group: await task_group.start(self._track_status, sub_status) await task_group.start(self._track_feedback, sub_feedback) await task_group.start(self._track_result, sub_result) task_status.started() await self._terminated.wait() task_group.cancel_scope.cancel()
async def non_main(*, task_status: TaskStatus) -> None: task_status.started(anyio.get_current_task().name)
async def taskfunc(*, task_status: TaskStatus) -> NoReturn: task_status.started(asyncio.current_task()) await sleep(5) pytest.fail("Execution should never reach this point")
def taskfunc(*, task_status: TaskStatus) -> None: task_status.started(get_current_task().name)
def taskfunc(*, task_status: TaskStatus) -> NoReturn: task_status.started(2) raise Exception("foo")
def taskfunc(*, task_status: TaskStatus) -> None: task_status.started("foo")
async def task(*, task_status: TaskStatus) -> None: nonlocal acquired task_status.started() async with lock: acquired = True
def task_fn(*, task_status: TaskStatus) -> None: task_status.started("hello")
async def subtask(*, task_status: TaskStatus) -> None: nonlocal initial_parent_id, permanent_parent_id initial_parent_id = get_current_task().parent_id task_status.started() permanent_parent_id = get_current_task().parent_id
async def taskfunc(*, task_status: TaskStatus) -> None: task_status.started()