Exemplo n.º 1
0
    async def self_cancel(*, task_status: TaskStatus) -> None:
        nonlocal done
        task_status.started()
        with move_on_after(-1):
            await Event().wait()

        done = True
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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")
Exemplo n.º 6
0
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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
 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()
Exemplo n.º 10
0
 async def non_main(*, task_status: TaskStatus) -> None:
     task_status.started(anyio.get_current_task().name)
Exemplo n.º 11
0
 async def taskfunc(*, task_status: TaskStatus) -> NoReturn:
     task_status.started(asyncio.current_task())
     await sleep(5)
     pytest.fail("Execution should never reach this point")
Exemplo n.º 12
0
 def taskfunc(*, task_status: TaskStatus) -> None:
     task_status.started(get_current_task().name)
Exemplo n.º 13
0
 def taskfunc(*, task_status: TaskStatus) -> NoReturn:
     task_status.started(2)
     raise Exception("foo")
Exemplo n.º 14
0
 def taskfunc(*, task_status: TaskStatus) -> None:
     task_status.started("foo")
Exemplo n.º 15
0
 async def task(*, task_status: TaskStatus) -> None:
     nonlocal acquired
     task_status.started()
     async with lock:
         acquired = True
Exemplo n.º 16
0
 def task_fn(*, task_status: TaskStatus) -> None:
     task_status.started("hello")
Exemplo n.º 17
0
 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
Exemplo n.º 18
0
 async def taskfunc(*, task_status: TaskStatus) -> None:
     task_status.started()