我使用 Python 的多线程模块编写了一个小的 Python 脚本。
被调用的目标函数threading.Thread
接受 2 个参数(self
和另一个值)。TypeError: example() takes 2 positional arguments but 3 were given
但即使只给出了 2 个参数,我总是会收到以下错误。
import threading
import random
num=random.randint(1,999)
threadN=10 #number of processes
a="11" #testing value
class ExampleClass():
def __init__(self):
self.num=num
def example(self,a):
print(self.num)
print(a)
if __name__ == '__main__':
cl=ExampleClass()
while threadN>0:
threading.Thread(target=cl.example, args=(a)).start()
threadN-=1
任何帮助,将不胜感激!