-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmultiprocess_deal.py
37 lines (25 loc) · 1.05 KB
/
multiprocess_deal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import multiprocessing as mp
def process_deal(func_in, *args, **kwargs):
# cpu_count=mp.cpu_count()
process_deal = mp.Process(target=func_in, args=args, kwargs=kwargs)
return process_deal
def processes_deal(func_in):
pass
def processes_start(funcs_in):
for func_iter in funcs_in:
func_iter.start()
def proccess_join(funcs_in):
for func_iter in funcs_in:
func_iter.join()
def split_list_data(list_in):
cpu_count = mp.cpu_count()
slice_length = int(len(list_in) / cpu_count)
slices = [list_in[index * slice_length:min((index + 1) * slice_length, len(list_in))] for index in range(cpu_count)]
return slices
def split_dict_data(dict_in):
cpu_count = mp.cpu_count()
slice_length = int(len(dict_in) / cpu_count)
keys = list(dict_in.keys())
slices = [keys[index * slice_length:min((index + 1) * slice_length, len(keys))] for index in range(cpu_count)]
dict_slices_list = [{key_iter: dict_in[key_iter] for key_iter in slice_group_iter} for slice_group_iter in slices]
return dict_slices_list