LoginSignup
1
0

More than 5 years have passed since last update.

pythonでconcurrentでメモリがもりもり増大する

Posted at

それなりの量のテキストをそれなりに時間の掛かるREST APIにかけようと思って、concurrentを使って↓のような並列処理を書いたのだけど、使用メモリがあっという間に膨れ上がってプロセスが死ぬ。

executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
wait_executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)

def proc(line):
  # REST APIを呼び出す処理

def wait_task(future):
    future.result()

for line in sys.stdin:
    future = executor.submit(proc, line)
    wait_executor.submit(wait_task, future)

最後にstdinのループの最後にgc.collect()を入れたら使用メモリは50MBくらいで落ち着くようになったけど、正しい解決方法ってなんなんだろ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0