RuntimeError: thread.__init__() not called (Python)

0 min read 135 words

Today I got a really dumb error from Python.

RuntimeError: thread.init() not called

But luckily it’s really easy to fix!

Below is the code before (with the error):

class SomeThread(Thread):
    def __init__(self, myVar):
        self.sMyVar = str(myVar)
    def run(self):
        self.sMyVar = "bla.." + self.sMyVar

And now for the code that resolved the problem:

class SomeThread(Thread):
    def __init__(self, myVar):
        Thread.__init__(self)
        self.sMyVar = str(myVar)
    def run(self):
        self.sMyVar = "bla.." + self.sMyVar

If you have really bad eye-sight and can’t spot the difference between the 2 code block above 😛
What we do is add the following code in the beginning of the construct – or __init__ in Python:

Thread.__init__(self)

Also be aware that I originally did:

from threading import Thread

Which means I don’t have to instantiate it going forward using `threading.Thread`, instead I can do `Thread` alone.

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags