fix: fix test race condition
ref: N25B-301
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from asyncio import Task
|
||||
from collections.abc import Coroutine
|
||||
|
||||
import zmq
|
||||
@@ -75,8 +76,8 @@ class BaseAgent(ABC):
|
||||
await self.setup()
|
||||
|
||||
# Start processing inbox and ZMQ messages
|
||||
await self.add_behavior(self._process_inbox())
|
||||
await self.add_behavior(self._receive_internal_zmq_loop())
|
||||
self.add_behavior(self._process_inbox())
|
||||
self.add_behavior(self._receive_internal_zmq_loop())
|
||||
|
||||
async def stop(self):
|
||||
"""Stops the agent."""
|
||||
@@ -128,7 +129,7 @@ class BaseAgent(ABC):
|
||||
"""Override this to handle incoming messages."""
|
||||
raise NotImplementedError
|
||||
|
||||
async def add_behavior(self, coro: Coroutine):
|
||||
def add_behavior(self, coro: Coroutine) -> Task:
|
||||
"""
|
||||
Helper to add a behavior to the agent. To add asynchronous behavior to an agent, define
|
||||
an `async` function and add it to the task list by calling :func:`add_behavior`
|
||||
@@ -138,3 +139,4 @@ class BaseAgent(ABC):
|
||||
task = asyncio.create_task(coro)
|
||||
self._tasks.add(task)
|
||||
task.add_done_callback(self._tasks.discard)
|
||||
return task
|
||||
|
||||
Reference in New Issue
Block a user