Example #1
0
async def test_ensure_loop():
    """Test ensure_loop."""
    loop = asyncio.new_event_loop()
    assert ensure_loop(loop) == loop

    loop = asyncio.get_event_loop()
    assert ensure_loop(loop) != loop
Example #2
0
    def __init__(
        self, agent: "Agent", loop: Optional[AbstractEventLoop] = None
    ) -> None:
        """Init loop.

        :params agent: Agent or AEA to run.
        :params loop: optional asyncio event loop. if not specified a new loop will be created.
        """
        WithLogger.__init__(self, logger)
        self._agent: "Agent" = agent
        self.set_loop(ensure_loop(loop))
        self._tasks: List[asyncio.Task] = []
        self._state: AsyncState = AsyncState()
        self._exceptions: List[Exception] = []
Example #3
0
    def __init__(self,
                 agent: "Agent",
                 loop: Optional[AbstractEventLoop] = None) -> None:
        """
        Init runtime.

        :param agent: Agent to run.
        :param loop: optional event loop. if not provided a new one will be created.
        :return: None
        """
        self._agent: "Agent" = agent
        self._loop = ensure_loop(
            loop
        )  # TODO: decide who constructs loop: agent, runtime, multiplexer.
        self._state: AsyncState = AsyncState(RuntimeStates.initial)