Python Threading inside a class

前端 未结 3 534
鱼传尺愫
鱼传尺愫 2020-12-02 09:09

I recently started with python\'s threading module. After some trial and error I managed to get basic threading working using the following sample code given in most tutoria

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-02 10:00

    You can pass class instance to the thread:

    class SomeThread(threading.Thread):
        def __init__(self, count, instance):
            threading.Thread.__init__(self)
            self.instance = instance
    
        def run(self):
            print "Do something"
            self.instance.some_param = data
            self.instance.some_function()
    

提交回复
热议问题