Skip to main content

在多进程内维护一个消息队列,更方便的使用多进程

Project description

Convenient multiprocessing with Message Queues

pypi
中文

Features

  • Lightning-fast startup: New processes launch in just 10ms.
  • Lightning-fast execution: Sending code (with parameters) takes only 0.8ms.
  • Easy to use: Thanks to interactivity.py, minimal modifications are required.
  • Automatically suspends when idle, conserving resources.

Usage

(We recommend referring to example.py for guidance)

Creating Processes

import multiprocessing_mq as mq
my_pro = mq.Process(init=init_code, suspend=True, rest_time=0)

Parameters

  • init: Initialization code.
  • suspend: Whether to suspend.
  • rest_time: Sleep time.
  • process_events: Performs event loop while waiting for process to resume, preventing UI from freezing.

Usage

There are multiple ways to send tasks to child processes. Among them, using inter is the simplest.

inter

Create a virtual class to simulate the environment of a child process. For example, to retrieve the value of a inside the child process, you only need my_pro.inter.a. Running a function only requires my_pro.inter.a().

run_com

Run a function and wait for a return value.

run_com(self, code: str, args: dict = {}, process_events=None)
  • code: The code to execute.
  • args: Arguments (Note: args won't automatically pass parameters; you need to pass them yourself within code).
  • process_events: Performs an event loop while waiting for the process result, preventing the UI from freezing.

Note: run_com uses eval to execute functions, so you cannot use it to modify variable values (you can use run_without_return instead).

run_without_return

run_without_return(self, code: str, args: dict = {})

Run a function without waiting for a return value; internally uses exec.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multiprocessing_mq-0.5.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

multiprocessing_mq-0.5-py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page