agentscope.server.async_result_pool module

A pool used to store the async result.

class agentscope.server.async_result_pool.AsyncResultPool[源代码]

基类:ABC

Interface of Async Result Pool, used to store async results.

abstract prepare() int[源代码]

Prepare a slot for the async result.

返回:

The key of the async result.

返回类型:

int

abstract 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.

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 agentscope.server.async_result_pool.LocalPool(max_len: int, max_expire: int)[源代码]

基类:AsyncResultPool

Local pool for storing results.

__init__(max_len: int, max_expire: int) None[源代码]
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.

get(key: int, timeout: int = 5) bytes[源代码]

Get the value with timeout

class agentscope.server.async_result_pool.RedisPool(url: str, max_expire: int)[源代码]

基类:AsyncResultPool

Redis pool for storing results.

INCR_KEY = 'as_obj_id'
TASK_QUEUE_PREFIX = 'as_task_'
__init__(url: str, max_expire: int) None[源代码]

Init redis pool.

参数:
  • url (str) – The url of the redis server.

  • max_expire (int) – The max timeout of the result in the pool,

  • reached (when it is)

  • removed. (the oldest item will be)

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.

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.

agentscope.server.async_result_pool.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.