Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.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,我在Python中扩展线程类时遇到问题。这是我的简单代码: import threading class position: def __init__(self,id): self.id = id class foo(threading.Thread): def __init__(self): self.start = position(0) threading.Thread.__init__(self) def

我在Python中扩展线程类时遇到问题。这是我的简单代码:

import threading

class position:

    def __init__(self,id):
        self.id = id

class foo(threading.Thread):

    def __init__(self):
        self.start = position(0)
        threading.Thread.__init__(self)

    def run(self):
        pass

if __name__ == '__main__':
    f = foo()
    f.start()
显示的错误是:

Traceback (most recent call last):
  File "foo.py", line 19, in <module>
    f.start()
AttributeError: position instance has no __call__ method
回溯(最近一次呼叫最后一次):
文件“foo.py”,第19行,在
f、 开始()
AttributeError:position实例没有调用方法
错误在哪里?我花了3个小时寻找解决方案,但找不到。
我在工作中多次扩展了Thread类,但这次它不起作用。

您已经用
位置
实例覆盖了
开始
方法。以不同的方式命名您的
位置
属性

例如


您已经用
位置
实例覆盖了
开始
方法。以不同的方式命名您的
位置
属性

例如


您已经使用构造函数中的
start
字段隐藏了
线程.start
方法


重命名该字段(例如,将其重命名为startedAt),或者如果坚持将其命名为
start
,则使用
foo.start(f)

在构造函数中隐藏了
Thread.start
方法和
start
字段


重命名该字段(例如,将其重命名为startedAt),或者如果您坚持将其命名为
start
,请使用
foo.start(f)

是否可以“重做”源代码?我不明白你的意思。你能“重做”源代码吗?我不明白你的意思。
import threading

class position:

    def __init__(self,id):
        self.id = id

class foo(threading.Thread):

    def __init__(self):
        self.start_position = position(0)   # self.start is now unharmed
        threading.Thread.__init__(self)

    def run(self):
        pass

if __name__ == '__main__':
    f = foo()
    f.start()