LoginSignup
6
5

More than 3 years have passed since last update.

Pickleできないオブジェクトを扱う際の並列計算(pathos)

Posted at

概要

joblib, multiprocessingを利用して、プロセス並列計算をする時に、以下のようなエラーに遭遇した時の解決方法を紹介する。プロセス間通信に利用しているpickle化ができないことが原因である。

error1
TypeError: cannot pickle 'SwigPyObject' object
error2
PicklingError: Could not pickle the task to send it to the workers.

解決方法

pathosを使用する。pip install pathosでインストールできる。

code
# some_func, some_listは適当に作成してください
from pathos.multiprocessing import ProcessingPool
pool = ProcessingPool(nodes=4)
result_list = pool.map(lambda x: some_func(x), some_list)

おまけ

保存の際のpickle化であれば、dillを用いることで解決する。

参考

6
5
1

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
6
5