【问题标题】:Python - Exception in thread Thread-1 (in __bootstrap_inner)Python - 线程 Thread-1 中的异常(在 __bootstrap_inner 中)
【发布时间】:2016-10-30 20:27:35
【问题描述】:

我已经构建了一个 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" object is not callable 并且认为我一定将它用作变量并且它干扰了内置的 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”实例,而且它们都不是变量,所以我对导致错误的原因感到困惑。

任何想法将不胜感激。

谢谢

【问题讨论】:

    标签: python typeerror traceback


    【解决方案1】:

    它可能与 str() 内置函数无关。该消息告诉您self.function 属于type 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
    

    【讨论】:

    • 好的,这是我调用线程的方式:import threadingthreading.Timer(pooldb.checktime, pool_level).start()
    • 这里没有人是心灵感应的 ;-) 也就是说,没有人能猜到 pooldb.checktimepool_level 是什么。如果。例如,pool_level 绑定到一个字符串,那么您看到的错误正是您应该看到的。 stackoverflow.com/help/mcve
    • 抱歉,我不太确定您需要看什么才能提供帮助。 pool_level 是一个完整的函数。它显示在第 1255 行:link 和 pooldb.checktime 在第 94 行:link
    • 抱歉,我不愿意盯着超过 1000 行的代码,我怀疑其他人也不会。我之前给过你这个链接:。 stackoverflow.com/help/mcve 尽可能简化代码来重现任何人都可以运行的问题,然后您将很快获得帮助。您最初的问题几乎没有透露任何内容,而发布指向整个项目的链接则透露太多;-)
    • 顺便说一句,在创建Timer 之前尝试在行上记录repr(pool_level)。如果pool_level 实际上被反弹到一个字符串(这将解释一切),那将提供一个巨大的线索,即它反弹到的字符串的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多