Max
Max

Reputation: 1487

Python Thread subcalss: __init__ not called

I'm currently trying to write my own subclass of threading.Thread. However, it seems that the __init__ call to the subclass does not work, because I always get an AttributeError in the run function when I want to address my own class variables with self.x.

Here is my code:

class MonitoringWorker(threading.Thread):
    def __int__(self, threads_hashtag: int = 1, threads_image: int = 4, threads_user: int = 1):
        self.threads_hashtag = threads_hashtag
        self.threads_image = threads_image
        self.threads_user = threads_user

        self.queue_hashtag = Queue()
        self.queue_image_meta_first = Queue()
        self.queue_image_meta_second = Queue()
        self.queue_image_meta_third = Queue()
        self.queue_user = Queue()
        super().__init__()

    def run(self):
        workers_hashtag = [HashtagWorker(self.queue_hashtag, self.queue_image_meta_first, i) for i in range(self.threads_hashtag)]
        # do stuff


if __name__ == '__main__':
    m = MonitoringWorker()
    m.start()
    m.join()

Can some explain the behaviour?

Upvotes: 1

Views: 88

Answers (1)

You have a typo __init__ and not __int__ :)

Upvotes: 1

Related Questions