Wolfgang Kerzendorf
Wolfgang Kerzendorf

Reputation: 734

local variable 'sresult' referenced before assignment

I have had multiple problems trying to use PP. I am running python2.6 and pp 1.6.0 rc3. Using the following test code:

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")

gives me the following result:

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

Any help is greatly appreciated.

Upvotes: 1

Views: 3987

Answers (2)

Bite code
Bite code

Reputation: 597381

It's a bug in the pp library. Fix it, or wait for it to be fixed.

Upvotes: 0

jemfinch
jemfinch

Reputation: 2899

I can't read your code because it's not formatted properly, but I can tell you your exact problem: you're trying to modify a global variable named "sresult" from inside a function, but you did not add this line to the beginning of your function:

global sresult

If you don't declare a variable global, Python will assume it's local to the function if you try to assign it within the function, so when you try to modify or access it, Python will complain that you haven't yet "bound the local variable" (that is, assigned it or given it a value).

Upvotes: 2

Related Questions