agentscope.server.async_result_pool module
A pool used to store the async result.
- class AsyncResultPool[源代码]
基类:
ABC
Interface of Async Result Pool, used to store async results.
- abstract get(key: int, timeout: int = 5) bytes [源代码]
Get a value from the pool.
- 参数:
key (int) – The key of the value
timeout (int) – The timeout seconds to wait for the value.
- 返回:
The value
- 返回类型:
bytes
- 抛出:
TimeoutError – When the timeout is reached.
- class LocalPool(max_len: int, max_expire: int)[源代码]
-
Local pool for storing results.
- class RedisPool(url: str, max_expire: int)[源代码]
-
Redis pool for storing results.
- get(key: int, timeout: int = 5) bytes [源代码]
Get a value from the pool.
- 参数:
key (int) – The key of the value
timeout (int) – The timeout seconds to wait for the value.
- 返回:
The value
- 返回类型:
bytes
- 抛出:
TimeoutError – When the timeout is reached.
- prepare() int [源代码]
Prepare a slot for the async result.
- 返回:
The key of the async result.
- 返回类型:
int
- set(key: int, value: bytes) None [源代码]
Set a value to the pool.
- 参数:
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 [源代码]
Get the pool according to the type.
- 参数:
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.