Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 对象没有属性_Python_Multithreading - Fatal编程技术网

Python 对象没有属性

Python 对象没有属性,python,multithreading,Python,Multithreading,请帮助我的线程代码。就像 class MyThread(threading.Thread): # Create a class representing a thread of control def __init__(self,target): print 'thread created' self.target = target threading.Thread.__init__ ( self )

请帮助我的线程代码。就像

class MyThread(threading.Thread): # Create a class representing a thread of control
        def __init__(self,target):
            print 'thread created'
            self.target = target
            threading.Thread.__init__ ( self )
        def run (self):
            print 'running thread '
            while True:
                self.target()
     # Define class to allow thread to be stopped over time
        def __init__ (self, target):
            super(MyThread, self).__init__()
            self._stop = threading.Event()
            print "thread stopped"
        def stop (self):
            self._stop.set()
        def stopped (self):
            return self._stop.isSet()
但是,当我运行它时,它抱怨self.target()行:'MyThread'对象没有属性'target'


我该怎么做

您定义了两个init函数。第二个定义(不定义目标)覆盖第一个定义。

您定义了两个init函数。第二个定义(不定义目标)覆盖第一个定义。

嗯。。。您正在重写自己的init方法,该重写不会分配self.target变量。

嗯。。。您正在重写自己的init方法,该重写不会指定self.target变量