从函数内部创建python线程

2024-03-29 13:39:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在函数中创建一个线程,但收到一个错误

这是我的密码:

from threading import Thread

def threadFunction(parameter):
    print(parameter)

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

main()

我收到以下错误:

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

Tags: inselftargetparametermaindef错误args