melobot.mp

多进程支持

melobot.mp.Process

SpawnProcess 的别名

class melobot.mp.SpawnProcess[源代码]

基类:SpawnProcess

melobot 进程类(使用 spawn 模式生成子进程)

__init__(entry: str | PathLike[str] | Path, argv: list[str] | None = None, target: Callable[[...], object] | None = None, name: str | None = None, args: Iterable[Any] | None = None, kwargs: Mapping[str, Any] | None = None, *, daemon: bool | None = None) None[源代码]

初始化一个子进程对象

参数:
  • entry (str | PathLike[str] | Path) -- 子进程的入口模块(必须是文件)

  • argv (list[str] | None) -- 子进程的 argv,为空时使用默认设置

  • target (Callable[[...], object] | None) -- 子进程的目标函数

  • name (str | None) -- 子进程的标识名称,注意真实的进程名称与此参数不相等,只是包含

  • args (Iterable[Any] | None) -- 目标函数的参数

  • kwargs (Mapping[str, Any] | None) -- 目标函数的参数

  • daemon (bool | None) -- 是否是守护进程

返回类型:

None

melobot.mp.ProcessPool

SpawnProcessPool 的别名

class melobot.mp.SpawnProcessPool[源代码]

基类:Pool

melobot 进程池类(使用 spawn 模式生成子进程)

__init__(entry: str | PathLike[str] | Path, argv: list[str] | None = None, processes: int | None = None, initializer: Callable[[...], object] | None = None, initargs: Iterable[Any] | None = None, maxtasksperchild: int | None = None) None[源代码]

初始化一个进程池对象

参数:
  • entry (str | PathLike[str] | Path) -- 所有子进程的入口模块(必须是文件)

  • argv (list[str] | None) -- 所有子进程的 argv,为空时使用默认设置

  • processes (int | None) -- 进程数

  • initializer (Callable[[...], object] | None) -- 初始化函数

  • initargs (Iterable[Any] | None) -- 初始化函数的参数

  • maxtasksperchild (int | None) -- 每个子进程执行的任务数,达到此数时销毁并生成新进程

返回类型:

None

melobot.mp.ProcessPoolExecutor

SpawnProcessPoolExecutor 的别名

class melobot.mp.SpawnProcessPoolExecutor[源代码]

基类:ProcessPoolExecutor

melobot 进程池执行器类(使用 spawn 模式生成子进程)

__init__(entry: str | PathLike[str] | Path, argv: list[str] | None = None, max_workers: int | None = None, initializer: Callable[[...], object] | None = None, initargs: Iterable[Any] | None = None) None[源代码]

初始化一个进程池执行器对象

参数:
  • entry (str | PathLike[str] | Path) -- 所有子进程的入口模块(必须是文件)

  • argv (list[str] | None) -- 所有子进程的 argv,为空时使用默认设置

  • max_workers (int | None) -- worker(进程)的数量

  • initializer (Callable[[...], object] | None) -- 初始化函数

  • initargs (Iterable[Any] | None) -- 初始化函数的参数

返回类型:

None

class melobot.mp.PBox[源代码]

基类:object

__init__(value: ~typing_extensions.Any = <object object>, name: str | None = None, module: str | None = None, entry: str | ~os.PathLike[str] | ~pathlib.Path | None = None) None[源代码]

pickle 包装器

更改或指定需要 pickle 的对象的来源

参数:
  • value (Any) -- 和 name 二选一,指定需要 pickle 的对象,默认值为一个哨兵对象(表示无值)

  • name (str | None) -- 和 value 二选一,指定需要 pickle 的对象的名称

  • module (str | None) -- pickle 的对象的来源模块名,为空时映射到进程的入口模块

  • entry (str | PathLike[str] | Path | None) -- pickle 的对象的来源模块的路径,如果为空则只依赖于模块名进行加载

返回类型:

None