ProducerMixin

simple_producer_mixin module

创建和提交任务的最简单混入类

class aio_parallel_tools.aio_task_pool.core.mixins.producer_mixin.simple_producer_mixin.SimpleProducerMixin[源代码]

基类:object

Simple Producer Mixin.

依赖

queue (Property): message queue.

loop (Property): event loop.

size (Property): worker pool's size.

waiting_tasks_number (Property): Waiting task size in queue.

make_message (Method): make task to message

close_workers (Asynchronous Method): Send worker pool size's close signal to the queue.

close_workers_nowait_soft (Method): Send worker pool size's close signal to the queue with no wait.

close_workers_hard (Method): Cancel worker hardlly.

提供:

paused (Property): Check if user can submit tasks.

closed (Property): Check if the pool is closed.

start_accept (Method): Start Accept tasks.

pause (Method): Pause the task pool.

submit (Asynchronous Method): Submit task to the task pool.

submit_nowait (Method): Submit task to the task pool with no wait.

close_pool (Asynchronous Method): Send close signal to all worker.

close_pool_nowait (Method): Send close signal to all workers with no waiting.

async close_pool(close_worker_timeout: Union[int, float, None] = None, close_pool_timeout: int = 3, safe: bool = True) → None[源代码]

Close all workers and paused the task pool.

参数
  • close_worker_timeout (Union[int, float, None], optional) -- Timeout for closing all workers. Defaults to None.

  • close_pool_timeout (int, optional) -- Timeout for join left tasks. Defaults to 3.

  • safe (bool, optional) -- when getting exceptions, raise it or warning it. Defaults to True.

引发
  • te -- close workers timeout.

  • e -- unknown error when closing workers.

  • te -- waiting for left tasks done timeout

  • e -- unknown error when waiting for left tasks done

close_pool_nowait(soft: bool = True) → None[源代码]

Close all workers and paused the task pool without waiting.

参数

soft (bool, optional) -- if True, this interface will send Signal to task pool to close workers; else all workers will be cancel. Defaults to True.

property closed

Check if the pool is closed.

pause() → bool[源代码]

Pause the task pool.

返回

Check if The task pool is paused

返回类型

bool

property paused

Check if user can submit tasks.

If the task pool can accept new tasks,the result is False; else it's True.

返回

can submit or not.

返回类型

bool

start_accept()[源代码]

Start Accept tasks.

async submit(task_func: Callable[[Any], Any], *, func_args: List[Any] = [], func_kwargs: Dict[str, Any] = {}, blocking: bool = True, **kwargs) → Union[_asyncio.Future, Any][源代码]

Submit task to the task pool.

参数
  • task_func (Callable[[Any], Any]) -- The task function which will be called by the workers.

  • func_args (List[Any], optional) -- The positional parameters for the task function. Defaults to [].

  • func_kwargs (Dict[str, Any], optional) -- The keyword parameters for the task function. Defaults to {}.

  • blocking (bool, optional) -- Set if waiting for the task's result. Defaults to True.

引发

NotAvailable -- The task pool is paused

返回

if blocking is True, submit will return the result of the task; else it will return a future which you can await it to get the result.

返回类型

Union[asyncio.Future, Any]

submit_nowait(task_func: Callable[[Any], Any], *, func_args: List[Any] = [], func_kwargs: Dict[str, Any] = {}, **kwargs) → _asyncio.Future[源代码]

Submit task to the task pool with no wait.

参数
  • task_func (Callable[[Any], Any]) -- The task function which will be called by the workers.

  • func_args (List[Any], optional) -- The positional parameters for the task function. Defaults to [].

  • func_kwargs (Dict[str, Any], optional) -- The keyword parameters for the task function. Defaults to {}.

引发
  • NotAvailable -- The task pool is paused or

  • e -- other exception

  • NotAvailable -- task pool is full, can not put task any more

返回

a future which you can await it to get the result.

返回类型

asyncio.Future