Python 2 + multiprocessing.Pool.map是无休止的可迭代?

时间:2016-11-04 02:41:34

标签: python python-2.7 multiprocessing python-multiprocessing

下面的代码(python2)从不记录所有python进程 已启动,但没有日志消息,也没有保存记录。

任何线索?

def writer(record):
    log.debug("Writing {}/{}".format(
        threading.currentThread().getName(), record))
    record.save()
    return


if __name__ == '__main__':
    # this is class implementing cycling iterable
    # therefore it never ends
    streamer = simulation.streams.SimulationStreamer(cfg.config)

    p = multiprocessing.Pool(1)
    p.map(writer, streamer)

SimulationStreamer 类实现 iter 和next()方法。 这是它的implementation

因为它是无限可迭代的,所以我无法在类

中定义__len__方法

1 个答案:

答案 0 :(得分:1)

Pool.map will try to convert the iterable to a list找到它的长度。请改用p.imap