This is the first time I am using the multithreading in python. I found many documents in related to multithread and multi-processing in python 2.7.9 and researched also multi-threading link. But I didn't get clue how to implement my application. I am having application based on self.count, which is in the below code is 5. I have to create a 5 threads or process and when I call d.sum(1,2) This should call sum function in 5 different thread and execute in parallel and update the result in result dictionary with thread-name and result.
Now my current approach is happening serially. But I want to make this as parallel using thread or process. Please help in achieving this.
Thanks in advance. The code snippets are highly appreciated.
I have the code so far.
class Base(object):
def __init__(self):
self.count =5 # Count = 5 is used to create a
#number of thread or process to run parallel
def sum(self, a, b):
result = {}
for i in range(0,self.count):
result[i] = a + b
return result
def diff(self, a, b):
result = {}
for i in range(0,self.count):
result[i] = a - b
return result
def mull(self, a, b):
result = {}
for i in range(0,self.count):
result[i] = a * b
return result
def division(self, a, b):
result = {}
for i in range(0,self.count):
result[i] = a / b
return result
d = Base()
print d.sum(1,2)
print d.diff(2,1)