[New-bugs-announce] [issue16572] Bad multi-inheritance support in some libs like threading or multiprocessing

Thomas Chiroux report at bugs.python.org
Wed Nov 28 22:35:08 CET 2012


New submission from Thomas Chiroux:

when using multi-inheritance and super() in __init__(), super() tries to run each constructor once.
For this to work correctly, it is needed to call super() in each constructor, including for Classes directly inherited from object.

The sample below does not execute correctly because threading.Thread constructor does not call super()
(and because Thread inherit from _Verbose, _Verbose should also call super() )

Sample:
from threading import Thread


class Foo(object):
    def __init__(self):
        super(Foo, self).__init__()
        print('Foo constructor')
        self.param1 = 'foo param1'


class Bar(Thread, Foo):
    def __init__(self):
        super(Bar, self).__init__()
        print('Bar constructor')
        self.another_param1 = "bar another_param1"

    def run(self):
        print("Running (%s - %s)" % (self.another_param1, self.param1))


if __name__ == '__main__':
    threads = []
    for i in range(1, 10):
        thread = Bar()
        threads.append(thread)
        thread.start()

    for thread in threads:
        thread.join()


This sample work by simply inverting Thread and Foo :

(...)
class Bar(Foo, Thread):
(...)

The sample is about threading.Thread, but it's also the same for multiprocessing.Process, and maybe for other modules in stdlib.

attached is a proposed path for threading.Tread in 2.7

I've tested the issue and have the same behavior in 2.7 and in 3.3

----------
components: Library (Lib)
files: diff_threading.py_2.7.patch
keywords: patch
messages: 176576
nosy: thomas.chiroux
priority: normal
severity: normal
status: open
title: Bad multi-inheritance support in some libs like threading or multiprocessing
type: behavior
versions: Python 2.7, Python 3.3
Added file: http://bugs.python.org/file28150/diff_threading.py_2.7.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16572>
_______________________________________


More information about the New-bugs-announce mailing list