I want to use multi-threading to get the longest substring among a set of strings. The following code works. HOWEVER, when I opened task manager, only around 40% of CPU was utilized. Why? How can I maximize the CPU power?
def longest_substring(s, t, score, j):
match = difflib.SequenceMatcher(None, s, t).get_matching_blocks()
char_num = []
for i in match:
char_num.append(i.size)
score[j] = max(char_num)
for i in range(m):
score = [None]*n
s = df.loc[i, 'ocr']
threads = [threading.Thread(target=longest_substring, args=(s, db.loc[j, 'ocr'], score, j)) for j in range(n)]
for t in threads:
t.start()
for t in threads:
t.join()