2014-10-06 12 views
0

我試圖使用並行python爲了做一些分佈式基準測試(本質上,協調和運行一些機器上的代碼從一箇中央服務器)。我的代碼工作得很好,直到我將功能移到一個單獨的包中。從那時起,我一直在收到ImportError: No module named some.module.pp_test獲取「ImportError:No module named」與包中的並行python和方法

我的問題實際上是雙重的:有沒有人遇到這個問題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 
+0

我結束了使用dispy而不是平行python ... – 2014-10-09 13:21:00

回答

0

dill不會pp開箱工作,因爲pp不序列化Python對象 - pp提取對象的源代碼(如Python標準庫中的inspect模塊)。

爲了使pp使用dill(實際上dill.source,這是由inspect增強dill),你必須使用的pp叉叫ppftppft安裝爲pp(即導入時使用import pp),但它具有更強的源檢查功能,因此您可以自動「序列化」大多數python對象,並自動跟蹤其依賴關係。

獲取ppft這裏:https://github.com/uqfoundation

ppftpip安裝和Python 3.x兼容。