如何高效使用Python中的pool.imap_unordered?

2024-10-01 04:55:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python多处理imap.无序怀着很大的期望。 然而,我的进程在深度睡眠中等待I/O

numofSimulations=10
chromNamesList=['chr1', 'chr2', 'chr3', 'chr4', 'chr5', 'chr6', 'chr7', 'chrX', 'chr8', 'chr9', 'chr10', 'chr11', 'chr12', 'chr13', 'chr14', 'chr15', 'chr16', 'chr17', 'chr18', 'chr20', 'chrY', 'chr19', 'chr22', 'chr21', 'chrM']
sim_nums = range(0, numofSimulations+1)
sim_num_chr_tuples=((sim_num,chrLong) for sim_num in sim_nums for chrLong in chromNamesList)

for arrayList in pool.imap_unordered(prepare_data_fill_arrays, (fillInputList(simNum,chrLong,x,y,z,a,b,c) for simNum,chrLong in sim_num_chr_tuples),chunksize=1):

    print('Worker pid %s in accumulate' %str(os.getpid()))
    array1 = arrayList[0]
    array2 = arrayList[1]
    accumulateArray(accumulatedArray1, array1)
    accumulateArray(accumulatedArray2, array2)

在这个伪代码中,我为每个simNum和chrLong对调用imap\u unordered。 我用不同的染色体提交相同的模拟数字,这样他们就不会试图在同一时间读取相同的色度输入文件。你知道吗

fillInputList只填充输入列表。你知道吗

prepare_data_fill_arrays读取基于染色体的文件并填充数组。你知道吗

然而,既然imap\ U无序是按不同染色体的顺序同时提交的,为什么进程还要等待呢?你知道吗

为什么

Worker id XXXX in accumulate

在准备\数据\填充\数组中写入任何注释之前写入?你知道吗


Tags: infor进程simnum无序imap染色体