Ubuntu OSでPython 3.5を使用して私のプログラムの出力をファイルに書き込もうとしています。ここで私がマルチスレッドを試みる前に最初に試したことがあります。Python 3.5でプログラムMultiThreadを作成しようとしましたが失敗しました
from fuzzywuzzy import process, fuzz
import ast
def people(email):
#Checking the names of people with fuzzywuzzy library of python
return([returns result])
writel = open (r'output.csv','w',encoding='utf-8',errors='ignore')
with open ('emailfile.txt','r',encoding='ascii',errors='ignore') as Filepointer:
result = []
for line in Filepointer.readlines():
count += 1
data = people(line.strip())
if data is not "":
result.append(data)
for data in result:
writel.write(str(data) + "\n")
writel.close()
は、それから私は、次のコードを使ってPython 3にマルチスレッド化しようとしました:
from fuzzywuzzy import process, fuzz
import ast
from concurrent.futures import ThreadPoolExecutor
import threading
global FinalOutput
def people(email):
#Checking the names of people with fuzzywuzzy library of python
FinalOutput.append([appends returned result])
print (FinalOutput)
return
threads = []
writel = open (r'output.csv','w',encoding='utf-8',errors='ignore')
count = 0
pool = ThreadPoolExecutor(max_workers=10)
with open ('emailfile.txt','r',encoding='ascii',errors='ignore') as Filepointer:
for line in Filepointer.readlines():
pool.submit(people,line.strip())
pool.shutdown(wait=True)
for data in FinalOutput:
writel.write(str(data) + "\n")
writel.close()
上記のコードは次のエラー生成:
Segmentation fault (core dumped)
を私はに関連StackOverflowの中のスレッドを経ていこの問題は解決されませんでした。私はまだ同じエラーが発生します。
コードを実行するために必要なことを教えてください。
なぜマルチスレッド化したいですか? –
入力ファイルが膨大で、ロジックの実行に時間がかかっていたため、以前のプロセスではシングルスレッドのみを使用していたため、プロセスがマルチスレッド化されると考えました。したがって、マルチスレッドは確実に完全なプロセスを向上させます。だから私はそれを考えました。 –
これは[mcve]ではありません。例 'FinalOutput.append([email、names [0] [0]、names [0] [1])'は有効な構文ではなく、 'names'も定義されていません(' FinalOutput'も定義されていません)。 –