Python 控制多線程
import threading
t1=threading.Thread(target=func, args=(n_real_cells, adata))
t1.start()#啟動線程
t1.join()#線程優(yōu)先
Python的apply并行運算pandarallel模塊
from pandarallel import pandarallel
num_cores=4
pandarallel.initialize(progress_bar=True,nb_workers=num_cores)
def sum_fun(a,b):
print('test'+b)
return sum([a,a+2,3])
lpd=pd.Series(range(len(pN))).parallel_apply(sum_fun,b='!')
R 控制多線程
require(parallel)
cl <- makeCluster(num.cores) #開啟多線程
output2 <- mclapply(as.list(1:length(pN)),
FUN = parallel_paramSweep,
PCs,
sct,mc.cores=num.cores) #設(shè)置線程數(shù)
stopCluster(cl) #結(jié)束多線程