在多进程内维护一个消息队列,更方便的使用多进程
Project description
Convenient multiprocessing with Message Queues
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 withincode
).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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file multiprocessing_mq-0.5.tar.gz
.
File metadata
- Download URL: multiprocessing_mq-0.5.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 979199232a38171efda7a1946e11813600723eb3ee4e393ab6b9e0b8ecdb9675 |
|
MD5 | e184fbe37e18eb379ec116abb94165d4 |
|
BLAKE2b-256 | c71e7b56309b04309b6f9602b9d3033e4bb7aaec6ac860747cc0a2f0ff9f2898 |
File details
Details for the file multiprocessing_mq-0.5-py3-none-any.whl
.
File metadata
- Download URL: multiprocessing_mq-0.5-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0977692e4f17020d9d1026026f2e472fdaa6b7d0542c1b906f01074cfc414f3 |
|
MD5 | 056240f4d513374bb1249a449091bade |
|
BLAKE2b-256 | 428888708a91c41ad41274c5f2fce3ea744b823069d65be2905e4635278dac98 |