I have several txt files, each with about a million lines, and it takes about a minute to search for equalities. The files are saved as 0.txt, 1.txt, 2.txt,... for convenience, in_1 and searchType are user-given inputs.
class ResearchManager():
def __init__(self,searchType,in_1,file):
self.file = file
self.searchType = searchType
self.in_1 = in_1
def Search(self):
current_db = open(str(self.file) + ".txt",'r')
.
.
.
#Current file processing
if __name__ == '__main__':
n_file = 35
for number in range(n_file):
RM = ResearchManager(input_n, input_1, number)
RM.Search()
I would like to optimise the search process using multiprocessing, but I have not succeeded. Is there any way of doing this? Thank you.
Edit.
I was able to use threads in this way:
class ResearchManager(threading.Thread):
def __init__(self, searchType, in_1, file):
threading.Thread.__init__(self)
self.file = file
self.searchType = searchType
self.in_1 = in_1
def run(self):
current_db = open(str(self.file) + ".txt",'r')
.
.
.
#Current file processing
...
threads=[]
for number in range(n_file+1):
threads.append(ResearchManager(input_n,input_1,number))
start=time.time()
for t in threads:
t.start()
for t in threads:
t.join()
end=time.time()
But the total execution time is even a few seconds longer than the normal for loop.