views:

158

answers:

1

Hi,

Small question. Every object I know of in python can take care of its base class initialization by calling

super(BaseClass, self).__init__()

This doesn't seem to be the case with a subclass of threading.Thread, since if I try this in SubClass.__init__(), I get:

RuntimeError: thread.__init__() not called

What gives? I looked at the source for threading.Thread and it looks like that __init__ method should set Thread.__initialized = True. I see that all examples use the following __init__:

class YourThread(threading.Thread):
    def __init__(self, *args):
        threading.Thread.__init__(self)
        # whatev else

But why?

+5  A: 

This works fine:

>>> class MyThread(threading.Thread):
...   def __init__(self):
...     super(MyThread, self).__init__()

I think your code's bug is that you're passing the base class, rather than the current class, to super -- i.e. you're calling super(threading.Thread, ..., and that's just wrong. Hard to say since you don't show your failing code, but that's what I infer obliquely from the language you're using!-)

Alex Martelli
I think you have inferred correctly
gnibbler
Hi yes you are right. Doh! Thanks.
DGGenuine