1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pyinstaller と multiprocessing 併用

Last updated at Posted at 2024-09-11

並列処理のための標準モジュール multiprocessing を使ったコードを Pyinstaller で固める

注意:とんでもないことが起きます。
multiprocessing を使ったコードを
単にpyinstallerしてバイナリ化したモジュールを走らせると、、、
 1つ実行して停まるたびに、本来は存在しないはずの次の実行を延々と繰り返しよる!
  下手すると同一処理が無数に走って世界を埋め尽します。
それだけでなく、このプロセスが繰り返し時に重複して走るために、重複していなければ起きない様々な例外を引き起こしてエラーメッセージでコンソールが埋め尽くされ何が原因か分からなくなるという副作用もあります。

重要:最初に freeze_support() を呼ぶ

WindowsでもPosixでもfreeze_support()は必要です。
2024年9月現在、「freeze_support() は Windows 限定」という説明は誤情報のようです。

if _ _ name _ _==' _ _ main _ _': の直後に置けという説示も見かけるが、本質的にはmultiprocessingを動かす前にmultiprocessing.freeze_support()を呼べ、ということでしょう。
multiprocessingの最初のインポートの直後に呼んでしまってよいと思う。

↓ 本家ドキュメントのP29あたりにあります。
https://pyinstaller.org/_/downloads/en/v6.4.0/pdf/

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?