Generator problem: parent class not seen

Russell E. Owen rowen at
Wed Feb 1 22:00:39 CET 2012

I have an odd and very intermittent problem in Python script. 
Occasionally it fails with this error:

Traceback (most recent call last):
"/Applications/APO/", line 884, in run
"/Applications/APO/", line 1690, in initAll
TypeError: unbound method initAll() must be called with BaseFocusScript 
instance as first argument (got ScriptClass instance instead)
self=<ScriptClass object at 0x2066b410>; class hierarchy=[(<class 
'TUI.Base.BaseFocusScript.ImagerFocusScript'>, (<class 
'TUI.Base.BaseFocusScript.BaseFocusScript'>,)), [(<class 'ScriptClass'>, 
(<class 'TUI.Base.BaseFocusScript.ImagerFocusScript'>,))]]

The code looks like this:

    def run(self, sr):
        except Exception:
            sys.stderr.write("self=%r; class hierarchy=%s\n" % (self, 

As a detail that may be important: the code is a generator that is being 
run by a script runner class (an instance of which is passed into the 
run function as argument sr). When the user starts a script the script 
runner calls the script's "run" generator. The script runner calls the 
run generator again later when conditions are right (e.g. data that is 
being waited for arrives, a time limit is reached...). In this case the 
failure occurs at the very start of the script, so a yield has not yet 

I am puzzled why Python thinks the class type is wrong, given the output 
of inspect.getclasstree. Any ideas on what might be wrong and how to 
track it down (and why it would be so intermittent)?

-- Russell

More information about the Python-list mailing list