I am trying to use multithreading in python. I wrote the following code to start. It is supposed to compute, in parallel, the squares of numbers contained in a list and to return the result in a list named 'result'. I wrote this in order to parallelize a script that contains a for loop.
However, I get a TypeError telling me that 'int object is not callable'. I am guessing this is because of this line of code: thr.append(threading.Thread(target=square(k))): In the examples I read, target was a function. But in my example, I will need to call the same function with different arguments. How can I do that?
>>> def square(c):
... return c^2
... result.append(c^2)
...
>>> def sqr():
... thr = []
... for k in l:
... thr.append(threading.Thread(target=square(k)))
... for t in thr:
... t.start()
... for i in thr:
... t.join()
c**2squaresc.c^2performs XOR.