agentscope.server.async_result_pool module
A pool used to store the async result.
- class AsyncResultPool[source]
Bases:
ABC
Interface of Async Result Pool, used to store async results.
- abstract get(key: int, timeout: int = 5) bytes [source]
Get a value from the pool.
- Parameters:
key (int) – The key of the value
timeout (int) – The timeout seconds to wait for the value.
- Returns:
The value
- Return type:
bytes
- Raises:
TimeoutError – When the timeout is reached.
- class LocalPool(max_len: int, max_expire: int)[source]
Bases:
AsyncResultPool
Local pool for storing results.
- class RedisPool(url: str, max_expire: int)[source]
Bases:
AsyncResultPool
Redis pool for storing results.
- get(key: int, timeout: int = 5) bytes [source]
Get a value from the pool.
- Parameters:
key (int) – The key of the value
timeout (int) – The timeout seconds to wait for the value.
- Returns:
The value
- Return type:
bytes
- Raises:
TimeoutError – When the timeout is reached.
- prepare() int [source]
Prepare a slot for the async result.
- Returns:
The key of the async result.
- Return type:
int
- set(key: int, value: bytes) None [source]
Set a value to the pool.
- Parameters:
key (int) – The key of the value.
value (bytes) – The value to be set.
- INCR_KEY = 'as_obj_id'
- TASK_QUEUE_PREFIX = 'as_task_'
- get_pool(pool_type: str = 'local', max_expire: int = 7200, max_len: int = 8192, redis_url: str = 'redis://localhost:6379') AsyncResultPool [source]
Get the pool according to the type.
- Parameters:
pool_type (str) – The type of the pool, can be local or redis, default is local.
max_expire (int) – The max expire time of the result in the pool, when it is reached, the oldest item will be removed.
max_len (int) – The max length of the pool.
redis_url (str) – The address of the redis server.