在多进程内维护一个消息队列,更方便的使用多进程
Project description
带有消息队列的方便多进程
特性
- 极速启动: 启动新进程仅需 10ms
- 极速运行: 发送代码(带参数),仅需 0.8ms
- 简单使用: 得益于
interactivity.py
只需要少量修改即可完成 - 无任务时自动挂起,节省资源
使用
(建议参照 example.py
)
创建进程
import multiprocessing_mq as mq
my_pro = mq.Process(init=init_code, suspend=True, rest_time=0)
参数
init
: 初始化代码suspend
: 是否挂起rest_time
: 休眠时间process_events
: 等待进程恢复时进行事件循环,防止界面卡死
使用
有多种方式可以向子进程发送任务。其中,使用 inter
是最简单的方式
inter
通过创建一个虚拟类来模拟子进程的环境
例如获取子进程内 a
的值只需要 my_pro.inter.a
运行函数只需要 my_pro.inter.a()
run_com
运行函数并等待返回值
run_com(self, code:str,args:dict = {}, process_events = None)
code
: 要执行的代码args
: 参数 (注意:args
不会自动帮你把参数传进去,你需要在code
自己传进去)process_events
: 等待进程结果时进行事件循环,防止界面卡死
注意: run_com
使用 eval
来执行函数,因此你不能用它来修改变量值(你可以使用 run_without_return
)
run_without_return
run_without_return(self, code:str, args:dict = {})
运行函数,不等待函数值,内部使用 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
multiprocessing_mq-0.1.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for multiprocessing_mq-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36a17ec2191ac066abe0b2d84130f6ed1ae11e9880618b8c2d680abbc1e91c6e |
|
MD5 | 77bfc4511aae6623eabd6efc704552d6 |
|
BLAKE2b-256 | 1027d7ce261f35000c3feb79c170a9770da8f1bf944c6bee89633a0e103770c1 |