非常に興味深いと思いましたが、その理由はわかりません: 私の Python スクリプトの 1 つは、32 ビットの win 2003 マシン(20% またはそれ以下の CPU 使用率) で問題なく実行されますが、まったく同じスクリプトが 64 ではほぼ100% の CPU を消費します。ビットウィン2008マシン。2 台のマシンは同じレベルのハードウェアを備えています。
threading
基本的に、スクリプトはモジュールを使用してマルチスレッド化され、多数mechanize
の Web ページから特定の結果をスクレイピングします。
とにかく、その 64 ビット OS で CPU 使用率が高い理由は何ですか?
編集:
マルチスレッド スクリプトを 32 ビットから 64 ビットに移行する際の一般的な注意事項を実際に見つけようとしています。
OK、コードは次のとおりです。
def SpawnThreads(amounts, urls_queue, proxies_queue):
for counter in range(amounts):
new_thread = threading.Thread(target = CheckResults, args = (urls_queue, proxies_queue, ))
new_thread.start()
def CheckResults(urls_queue, proxies_queue):
if urls_queue.empty():
return 1
if proxies_queue.empty():
return 1
get url from urls_queue
get proxy from proxies_queue
get html source of url
put proxy back to proxies_queue if everything's all right
spawn_a_new_thread = threading.Thread(target = SpawnThreads, args = (1, urls_queue, proxies_queue)
spawn_a_new_thread.start()
if __name__ == "__main__":
put all urls into urls_queue
put all proxies into proxies_queue
SpawnThreads(100, urls_queue, proxies_queue)