0

我正在尝试使用并行 python 来进行一些分布式基准测试(本质上,在来自中央服务器的一组机器上协调和运行一些代码)。在我将功能移动到单独的包之前,我的代码运行良好。从那以后,我不断得到ImportError: No module named some.module.pp_test

我的问题实际上是双重的:有没有人遇到过这个问题pp,如果是,如何解决?我尝试使用dillimport dill),但没有帮助。此外,parallelpython 是否有一个很好的替代品,不需要任何额外的基础设施?

我得到的确切错误是:

RUNNING TEST
Waiting for hosts to finish booting....A fatal error has occured during the function execution
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/ppworker.py", line 86, in run
    __args = pickle.loads(__sargs)
ImportError: No module named some.module.pp_test
Caught exception in the run phase 'NoneType' object is not iterable
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    p.ping_pong()
  File "/home/ubuntu/workspace/pp-test/some/module/pp_test.py", line 5, in ping_pong
    a_test.run()
  File "/home/ubuntu/workspace/pp-test/some/module/pp_test.py", line 27, in run
    pong, hostname = ping()
TypeError: 'NoneType' object is not iterable

代码的结构是这样的:

pp-test/
       test.py
       some/
            __init__.py
            module/
                   __init__.py
                   pp_test.py

test.py实现为:

from some.module.pp_test import MWE

p = MWE()
p.ping_pong()

虽然pp_test.py是:

class MWE():
  def ping_pong(self):
    print "RUNNING TEST "
    a_test = PPTester()
    a_test.run()

import pp
import time
from sys import stdout, exit

class PPTester(object):
  def run(self):
    try:
        ppservers = ('10.10.10.10', )
        time.sleep(5)
        job_server = pp.Server(0, ppservers=ppservers)
        stdout.write("Waiting for hosts to finish booting...")
        while len(job_server.get_active_nodes()) - 1 < len(ppservers):
            stdout.write(".")
            stdout.flush()
            time.sleep(1)

        ppmodules = ()
        pings = [(server, job_server.submit(self.run_pong, modules=ppmodules)) for server in ppservers]
        for server, ping in pings:
            pong, hostname = ping()
            print "Host ", hostname, " is alive!"

        print "All servers booted up, starting benchmarks..."
        job_server.print_stats()
    except Exception as e:
        print "Caught exception in the run phase", e
        raise
    pass

  def run_pong(self):
    import subprocess
    p = subprocess.Popen("hostname", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    (output, err) = p.communicate()
    p_status = p.wait()

    return "pong ", output
4

1 回答 1

0

dill不能pp开箱即用,因为pp不序列化 python 对象——pp提取对象的源代码(如inspect标准 python 库中的模块)。

要启用pp使用dill(实际上dill.sourceinspect由 增强的dill),您必须使用pp被调用的分支ppftppft安装为pp(即使用 导入import pp),但它具有更强大的源代码检查功能,因此您可以自动“序列化”大多数 python 对象并ppft自动跟踪它们的依赖关系。

ppft到这里:https : //github.com/uqfoundation

ppft也是可pip安装的和python3.x兼容的。

于 2015-02-03T18:16:33.510 回答