Python 3.x中的多线程错误问题

时间:2019-02-13 21:42:04

标签: python-3.x multithreading fuzzywuzzy

我正在尝试在Python 3.x中设置多线程代码。我创建了两个函数来比平时更快地模糊匹配某些数据。

我正在尝试将客户端数据分为两部分并分别运行。

当我尝试启动线程时,收到如下错误消息:

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

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

这是我的代码:

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))

0 个答案:

没有答案