-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparallel.py
More file actions
30 lines (22 loc) · 1.16 KB
/
parallel.py
File metadata and controls
30 lines (22 loc) · 1.16 KB
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
####Esempio definitivo in:
###############################
#Esempio master: hai uno script molto bello che chiami con python prog.py --id 678
#Ora di id ce ne sono parecchio --> parallelizza cosi'
import os
from multiprocessing import Pool
def Looper(farm_id):
print farm_id
os.system('python BDT_Model_predictor.py -o farms_check --create --id '+str(farm_id))
farms_ids=[247, 374, 546, 606, 626, 666, 667, 686, 740, 741, 742, 743, 744, 1044, 1045, 1147, 1186, 1187, 1252, 1254, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366,\
1367] #1226
pool = Pool(processes=2)
###case 1: function takes 1 argument
pool_result = [pool.apply_async(Looper, args=(farm,)) for farm in farms_ids]
for i in pool_result:
result = i.get()
#func takes 2 arguments
pool_result = [pool.apply_async(func, args=(arg1, arg2)) for arg1 in args_loop_list]
for i in pool_result:
result = i.get()
## Then, to kill this wild beast here in shell
#kill -9 $(ps -ef | grep gfasane | grep python | grep name_of_main_program | awk '{print$2}')