I wrote a small python script using Python's threading module for multi-threading.
The target function that gets called by threading.Thread
takes 2 arguments (self
and another value). But I always get the following error TypeError: example() takes 2 positional arguments but 3 were given
even if only 2 arguments are given.
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
Any help would be appreciated!