Python Tutorial on Multithreading

Alexander Kapps alex.kapps at
Mon Feb 21 18:04:32 EST 2011

On 21.02.2011 23:30, KevinSimonson wrote:
> I've been teaching myself Python from the tutorial routed at "http://
>".  It's worked out pretty
> well, but when I copied its multithreading example from the bottom of
> the page at "
> python_multithreading.htm" and tried to run it I got the error
> messages:
> C:\Users\kvnsmnsn\Python>python
> Traceback (most recent call last):
>    File "", line 38, in<module>
>      thread = myThread(threadID, tName, workQueue)
>    File "", line 10, in __init__
> = name
>    File "C:\Python27\lib\", line 667, in name
>      assert self.__initialized, "Thread.__init__() not called"
> AssertionError: Thread.__init__() not called
> I don't really understand why it's giving me these messages.
> <__initialized>  gets set to<True>  when<__init__()>  gets called.
> Granted my Python program calls<__init__()>  with only one parameter,
> and the constructor in "" takes _seven_ parameters, but
> all but one have default values, so a call with just one parameter
> should be legal.  Why then is<__initialized>  getting set to<True>?
> My code follows.

That tutorial seems to be wrong.

According to the official docs:

"If the subclass overrides the constructor, it must make sure to 
invoke the base class constructor (Thread.__init__()) before doing 
anything else to the thread."

So, change your __init__ to this:

class myThread (threading.Thread):
     def __init__(self, threadID, name, q):
         self.threadID = threadID = name
         self.q = q


More information about the Python-list mailing list