在赋值之前引用的局部变量'sresult'

时间:2010-04-11 06:20:44

标签: python cluster-computing parallel-python

我在尝试使用PP时遇到了多个问题。我正在运行python2.6和pp 1.6.0 rc3。使用以下测试代码:

import pp
nodes=('mosura02','mosura03','mosura04','mosura05','mosura06',
       'mosura09','mosura10','mosura11','mosura12')

def pptester():
        js=pp.Server(ppservers=nodes)
        tmp=[]
        for i in range(200):
                tmp.append(js.submit(ppworktest,(),(),('os',)))
        return tmp

def ppworktest():
        return os.system("uname -a")

给我以下结果:

In [10]: Exception in thread run_local:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/wkerzend/python_coala/lib/python2.6/site-packages/pp.py", line 751, in _run_local
    job.finalize(sresult)
UnboundLocalError: local variable 'sresult' referenced before assignment

Exception in thread run_local:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/wkerzend/python_coala/lib/python2.6/site-packages/pp.py", line 751, in _run_local
    job.finalize(sresult)
UnboundLocalError: local variable 'sresult' referenced before assignment

Exception in thread run_local:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/wkerzend/python_coala/lib/python2.6/site-packages/pp.py", line 751, in _run_local
    job.finalize(sresult)
UnboundLocalError: local variable 'sresult' referenced before assignment

Exception in thread run_local:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/wkerzend/python_coala/lib/python2.6/site-packages/pp.py", line 751, in _run_local
    job.finalize(sresult)
UnboundLocalError: local variable 'sresult' referenced before assignment

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:2)

我无法读取您的代码,因为它的格式不正确,但我可以告诉您确切的问题:您正在尝试从函数内部修改名为“sresult”的全局变量,但您没有添加此行到你的功能的开头:

global sresult

如果你没有声明变量global,如果你尝试在函数中分配它,Python会认为它是函数的本地函数,因此当你尝试修改或访问它时,Python会抱怨你还没有“绑定局部变量”(即,为其赋值或赋值)。

答案 1 :(得分:0)

这是pp库中的一个错误。修复它,或等待它修复。