0

I'm trying to setup a multithread code in Python 3.x. I have created two functions to fuzzy match some data faster than usual.

I'm trying to split the client data in two parts and run it separately.

When I try to start the thread I receive an error message like this:

Original exception was:
TypeError: FuzzyThread1() takes 0 positional arguments but 2 were given

TypeError: FuzzyThread2() takes 0 positional arguments but 2 were given

Here's my code:

import _thread
from fuzzywuzzy import fuzz
import time
import datetime

similarity = 85
SplittedFilePath = "C:\\Users\\Erick.Batista\\Desktop\\PYTHON\Fuzzy\\FuzzyMatch - OwnScript\\EYData\\SplittedFiles\\"

starttimeT0 = time.time()

"""IMPORT DATABASES HERE!"""
ChronosFile = 'Medias.txt'
with open(ChronosFile) as f:
    contentB = f.readlines()
# Remove \n of each line
contentB = [x.strip() for x in contentB]

""" THREAD 1 - IMPORT CLIENT HALF DATA HERE! """
ClientData1 = 'BKG_Names_1.txt'
with open(ClientData1) as f:
    contentA1 = f.readlines()
# Remove \n of each line
contentA1 = [x.strip() for x in contentA1]


""" THREAD 2 - IMPORT OTHER HALF CLIENT DATA HERE!!! """
ClientData2 = 'BKG_Names_2.txt'
with open(ClientData2) as f:
    contentA2 = f.readlines()
# Remove \n of each line
contentA2 = [x.strip() for x in contentA2]

def FuzzyThread1():
    file1 = "C:\\Users\\Erick.Batista\\Desktop\\PYTHON\\Fuzzy\\FuzzyMatch - OwnScript\Results\\" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S" + "_Part1")
    file = open(file1 + '.txt', "a")
    file.write('Client Field | EY Field|Similarity\n')
    for i in contentA1:
        for y in contentB:
            if fuzz.ratio(i, y) >= similarity:
                file.write(str(i + ' | ' + y + '|' + str(fuzz.ratio(i, y)) + '\n'))
    file.close()

def FuzzyThread2():
    file2 = "C:\\Users\\Erick.Batista\\Desktop\\PYTHON\\Fuzzy\\FuzzyMatch - OwnScript\Results\\" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S" + "_Part2")
    file3 = open(file2 + '.txt', "a")
    file3.write('Client Field | EY Field|Similarity\n')
    for i in contentA2:
        for y in contentB:
            if fuzz.ratio(i, y) >= similarity:
                file3.write(str(i + ' | ' + y + '|' + str(fuzz.ratio(i, y)) + '\n'))
    file3.close()

_thread.start_new_thread(FuzzyThread1,("Thread-1",2))
_thread.start_new_thread(FuzzyThread2,("Thread-2",4))
print("It took TOTAL {:.2f} seconds to execute this code".format(time.time() - starttimeT0))
shreyshrey
  • 515
  • 6
  • 20
Erick Batista
  • 21
  • 1
  • 3
  • Relevant section from the manual: https://docs.python.org/3/library/_thread.html#_thread.start_new_thread – ForceBru Feb 13 '19 at 21:45
  • Hello, I've read the the documentation, but I still have a question about start and use multiple threads. I'm new to Python programming, could you be more specific please? – Erick Batista Feb 14 '19 at 13:08

0 Answers0