Python - 线程Thread-1中的异常(在__bootstrap_inner中)

时间:2016-10-30 20:27:36

标签: python typeerror traceback

我已经构建了一个python脚本,可以为我的池管理一堆不同的东西。我一直在添加更多功能,并在运行所有内容的Raspberry Pi上玩一些超时。今天我开始收到这个错误:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
  File "/usr/lib/python2.7/threading.py", line 1082, in run
self.function(*self.args, **self.kwargs)
TypeError: 'str' object is not callable

所以我开始阅读最后一部分(TypeError:' str"对象不可调用,并认为我必须将它用作变量,它干扰了内置的str函数。所以我查找了每个单独的实例,如果在我的代码中我可以找到str(1300行),这就是我找到的所有内容,所以现在我对实际导致问题的原因感到困惑(缩短为显示str的位置:

1) logger.info("Notify socket = {0}".format(str(s_adr)))
2) ph_value = str(line)
3)"/input/post.json?&node=" + str(pooldb.ph_node)
4) orp_value = str(line2)
5)"/input/post.json?&node=" + str(pooldb.orp_node)
6) current_military_time = int(datetime.datetime.now().strftime('%H%M'))

就是这样,在1300多行代码中,这些是' str'我能找到并且它们都不是变量所以我对导致错误的原因感到困惑。

非常感谢任何想法。

由于

1 个答案:

答案 0 :(得分:1)

它可能与str()内置无关。该消息告诉您self.function属于类型 str - 并且字符串实际上不可调用。像这样:

>>> 'ab'(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
>>> 23(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> [7](3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable

你应该看看你是如何创建线程的。例如,

>>> import threading
>>> t = threading.Thread(target="abc")
>>> t.start()
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
TypeError: 'str' object is not callable