Search code examples
pythontypeerrortraceback

Python - Exception in thread Thread-1 (in __bootstrap_inner)


I have built a python script that manages a bunch of different things for my pool. I have been adding more functions and playing with some timeouts on my Raspberry Pi that is running everything. Today I started getting this error:

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

So I started reading up on the last part (TypeError: 'str" object is not callable and figured I must have used it as a variable and it was interfering with the built-in str function. So I looked for every single instance if str in my code I could find (1300 lines) and this is all that I have found, so now I am stumped as to what could actually be causing the problem (shortened to show where the str is:

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'))

That is it, in 1300+ lines of code those are the only instances of 'str' that I can find and none of them are variables so I am confused as to what is causing the error.

Any ideas would be greatly appreciated.

Thanks


Solution

  • It probably has nothing to do with the str() builtin. The message is telling you that self.function is of type str - and strings in fact are not callable. Like so:

    >>> '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
    

    You should look instead at how you're creating threads. For example,

    >>> 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