【问题标题】:Is there a hidden possible deadlock in ppmap/parallel python?ppmap/parallel python 中是否存在隐藏的可能死锁?
【发布时间】:2012-04-27 14:33:32
【问题描述】:

我在使用 map 的并行版本时遇到了一些问题(ppmap 包装器,由 Kirk Strauser 实现)。

我尝试并行运行的函数对大量字符串(蛋白质序列)进行简单的正则表达式搜索,这些字符串是使用 BioPython 的 SeqIO 从文件系统中解析出来的。每个函数调用都使用自己的文件。

如果我使用法线贴图运行该函数,一切都会按预期运行。然而,当使用 ppmap 时,一些运行简单的冻结,没有 CPU 使用,主程序甚至没有对 KeyboardInterrupt 做出反应。此外,当我查看正在运行的进程时,工作人员仍然在那里(但不再使用任何 CPU)。

例如

/usr/bin/python -u /usr/local/lib/python2.7/dist-packages/pp-1.6.1-py2.7.egg/ppworker.py 2>/dev/null

此外,工作人员似乎没有冻结任何特定的数据输入 - 如果我手动终止进程并重新运行执行,它会在不同的点停止。 (所以我暂时采取了保留已完成条目的列表并多次重新启动程序。

有什么办法可以看出问题出在哪里?

我正在运行的代码示例:

def analyse_repeats(data):
    """
    Loads whole proteome in memory and then looks for repeats in sequences, 
    flags both real repeats and sequences not containing particular aminoacid
    """    
    (organism, organism_id, filename) = data

    import re
    letters = ['C','M','F','I','L','V','W','Y','A','G','T','S','Q','N','E','D','H','R','K','P']

    try:
        handle = open(filename)
        data = Bio.SeqIO.parse(handle, "fasta")

        records = [record for record in data]
        store_records = []
        for record in records:
            sequence = str(record.seq)
            uniprot_id = str(record.name)
            for letter in letters:
                items = set(re.compile("(%s+)" % tuple(([letter] * 1))).findall(sequence))     
                if items:
                    for item in items:
                        store_records.append((organism_id,len(item), uniprot_id, letter))
                else:
                    # letter not present in the string, "zero" repeat
                    store_records.append((organism_id,0, uniprot_id, letter))
        handle.close()
        return (organism,store_records)
    except IOError as e:
        print e
        return (organism, [])


res_generator = ppmap.ppmap(
    None, 
    analyse_repeats, 
    zip(todo_list, organism_ids, filenames)
)

for res in res_generator:  
    # process the output

如果我使用简单地图而不是 pmap,一切正常:

res_generator = map(
    analyse_repeats, 
    zip(todo_list, organism_ids, filenames)
)

【问题讨论】:

  • 在死锁消失之前,您可以从该代码示例中提取多少?
  • 好主意 - 将尝试并报告。

标签: python biopython parallel-python


【解决方案1】:

您可以尝试使用multiprocessing 模块中Pool 对象的一种方法(如map)。优点是它是内置的,不需要外部包。它也很好用。

默认情况下,它使用的工作进程与您的计算机的内核数量一样多,但您也可以指定更大的数量。

【讨论】:

    【解决方案2】:

    我可以建议使用 dispy (http://dispy.sourceforge.net) 吗?免责声明:我是作者。我知道它没有直接解决问题,但希望对您有所帮助。

    【讨论】:

    • 将对其进行研究 - 并可能将其用于下一个项目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多