This commit is contained in:
2025-08-15 13:48:05 +08:00
parent 92221832d6
commit 28118fbd88
3 changed files with 15 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
[metadata] [metadata]
# replace with your username: # replace with your username:
name = guan name = guan
version = 0.1.183 version = 0.1.185
author = guanjihuan author = guanjihuan
author_email = guanjihuan@163.com author_email = guanjihuan@163.com
description = An open source python package description = An open source python package

View File

@@ -1,6 +1,6 @@
Metadata-Version: 2.4 Metadata-Version: 2.4
Name: guan Name: guan
Version: 0.1.183 Version: 0.1.185
Summary: An open source python package Summary: An open source python package
Home-page: https://py.guanjihuan.com Home-page: https://py.guanjihuan.com
Author: guanjihuan Author: guanjihuan

View File

@@ -27,6 +27,19 @@ def try_except(function_name, *args, **kwargs):
except: except:
pass pass
# 使用 multiprocessing.Pool 实现自动分配任务并行
def parallel_calculation_with_multiprocessing_Pool(func, args_list=[1, 2, 3], show_time=0):
if __name__ == '__main__':
import multiprocessing
import time
start_time = time.time()
with multiprocessing.Pool() as pool:
result_array = pool.map(func, args_list)
end_time = time.time()
if show_time:
print(end_time - start_time)
return result_array
# 循环一个参数计算某个函数,并返回计算结果的数组 # 循环一个参数计算某个函数,并返回计算结果的数组
def loop_calculation_with_one_parameter(function_name, parameter_array): def loop_calculation_with_one_parameter(function_name, parameter_array):
import numpy as np import numpy as np