0

I am trying to create a thread within a function and am recieving an error

Here is my code:

from threading import Thread

def threadFunction(parameter):
    print(parameter)

def main():
        parameter = "abc"
        t = Thread(target='threadFunction', args=(parameter, ))
        t.start()
        t.join()

main()

And am receiving the following error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\tom\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\tom\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
TypeError: 'str' object is not callable

1 Answer 1

2
 t = Thread(target=threadFunction, args=(parameter, ))

No quotes. Pass the function value itself, not a string that happens to be spelled the same as when you defined it in source code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.