3

在 Parallel Python 中,为什么有必要在作业提交调用中包装函数传递所需的任何模块以及变量和命名空间 - 保留模块级“全局”变量的必要性有多大?(如果这就是发生的一切)

提交功能:

submit(self, func, args=(), depfuncs=(), modules=(), callback=None, callbackargs=(),group='default', globals=None)
    Submits function to the execution queue

    func - function to be executed
    args - tuple with arguments of the 'func'
    depfuncs - tuple with functions which might be called from 'func'
    modules - tuple with module names to import
    callback - callback function which will be called with argument 
        list equal to callbackargs+(result,) 
        as soon as calculation is done
    callbackargs - additional arguments for callback function
    group - job group, is used when wait(group) is called to wait for
    jobs in a given group to finish
    globals - dictionary from which all modules, functions and classes
    will be imported, for instance: globals=globals()
4

1 回答 1

3

这样做的原因pp是它为每个工作人员创建了一个新的 Python 解释器实例,它完全独立于之前或之后运行的任何内容。这确保了没有意外的副作用,例如__future__导入在工作进程中处于活动状态。这样做的问题是,它使事情变得更加复杂,而且根据我的经验pp,不是特别健壮。pp 确实试图让用户的事情变得更容易一些,但似乎引入的问题多于它在努力做到这一点时所解决的问题。

如果我要编写从一开始就设计用于集群的代码,我可能最终会使用pp. 但我发现调整现有代码以使其工作pp是一场噩梦。

于 2010-11-03T13:54:36.493 回答