Why does super().__init__ not work when subclassing threading.Thread?
multithreading, python, python-2.7
Solution
You are passing in `self` for the first parameter; don't do this. Remove `self` from the argument list and your call will work:
super(MyThread, self).__init__(group=group, target=target,
name=name, args=args, kwargs=kwargs,
verbose=verbose)
`super()` gives you a bound method, `self` is already being passed in for you (it is taken from the second argument to `super()`).
Since `group` is the first positional parameter in the `Thread.__init__()` method signature (after `self`), Python is applying your surplus `self` argument to the `group` parameter, and then finds an explicit `group=group` argument as well.
Problem
I wrote a simple program to use threads by subclassing `threading.Thread`. But if I use `super()` to call the `__init__` method of its parent class, namely `threading.Thread`, I got this error: ``` TypeError: __init__() got multiple values for keyword argument 'group' ``` If I use `threading.Thread.__init__()` directly, then there are no errors. My code: ``` class MyThread(threading.Thread): def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None): super(MyThread, self).__init__(self, group=group, target=target, name=name, args=args, kwargs=kwargs, verbose=verbose) # threading.Thread.__init__(self, group=group, target=target, # name=name, args=args, kwargs=kwargs, # verbose=verbose) self.args = args def run(self): print('a thread %d' % (self.args[0],)) if __name__ == '__main__': for i in xrange(5): thread = MyThread(args=(i,)) thread.start() ```