まず、私はマルチスレッドでの実際の経験がないと言ってこれをやりましょう。私が書いたこのスクリプトは、テキストファイルから〜4,400のアドレスを読み取り、アドレスを消去し、それをジオコードします。私の兄は、マルチスレッドを使ってスピードを上げる方法について言及しました。私は、あなたがただ一つのテキストファイルを使用しているならば、マルチスレッドが大きな違いをもたらさないことをオンラインで読んでいます。 1つのテキストファイルを2つのテキストファイルに分割しても機能しますか?とにかく、誰かがこのスクリプトにマルチスレッドやマルチプロセッシングを実装してスピードを上げる方法を教えてくれたら、本当に感謝しています。それができない場合は、理由を教えてもらえますか?ありがとう!このスクリプトでマルチスレッディング(またはマルチプロセッシング?)を実装しますか?
from geopy.geocoders import Bing
from geopy.exc import GeocoderTimedOut
geolocator = Bing('vadrPcGdNLSX5bPNL7tw~ySbwhthllg7rNA4VSJ-O4g~Ag28cbu9Slxp5Sh_AsBDuQ9WypPuEhl9pHVPCAkiPf4A9FgCBf3l0KyQTKKsLCHw')
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
def cleanAddress(dirty):
try:
clean = geolocator.geocode(dirty)
x = clean.address
address, city, zipcode, country = x.split(",")
address = address.lower()
if 'first' in address:
address = address.replace('first', '1st')
elif 'second' in address:
address = address.replace('second', '2nd')
elif 'third' in address:
address = address.replace('third', '3rd')
elif 'fourth' in address:
address = address.replace('fourth', '4th')
elif 'fifth' in address:
address = address.replace('fifth', '5th')
elif 'sixth' in address:
address = address.replace('ave', '')
address = address.replace('avenue', '')
address = address.replace('sixth', 'avenue of the americas')
elif '6th' in address:
address = address.replace('ave', '')
address = address.replace('avenue', '')
address = address.replace('6th', 'avenue of the americas')
elif 'seventh' in address:
address = address.replace('seventh', '7th')
elif 'fashion' in address:
address = address.replace('fashion', '7th')
elif 'eighth' in address:
address = address.replace('eighth', '8th')
elif 'ninth' in address:
address = address.replace('ninth', '9th')
elif 'tenth' in address:
address = address.replace('tenth', '10th')
elif 'eleventh' in address:
address = address.replace('eleventh', '11th')
zipcode = zipcode[3:]
print(address + ",", zipcode.lstrip() + ",", str(clean.latitude) + ",", str(clean.longitude))
except AttributeError:
print('Can not be cleaned')
except ValueError:
print('Can not be cleaned')
except GeocoderTimedOut as e:
print('Can not be cleaned')
def main():
root.update()
fpath = filedialog.askopenfilename()
f = open(fpath)
for line in f:
dirty = line + " nyc"
cleanAddress(dirty)
f.close()
if __name__ == '__main__':
main()
ありがとうございます。だから、このコードはテキストファイルを完全に実行するのにおよそ45分かかりますが、それはiPhoneをワイヤレスホットスポットとして使用しているときです(現在のところ、作業ネットワークはPythonにライブラリとの外部接続を許可していませんが、すぐに修正される)。このプログラムが平均速度のインターネット接続にどれくらい高速になるか考えていますか? – Harrison
ベスト "ありがとう"私は得ることができる私の答えのupvoteと回答としての質問を確認します。 「平均的な」スピードが何か、そして「リモート地理的位置情報サービス」がこれよりもこれをよりうまく処理できるかどうかわからないので、このプログラムが平均的なインターネット接続速度にどれだけ速くなるかを私はあなたに伝えることはできません。 –
これは愚かな質問かもしれませんが、テキストファイルを2つの部分に分割してPythonの2つのインスタンスを開き、同時に各半分にプログラムを実行するとうまくいくでしょうか? – Harrison