LoginSignup
0
1

【Python】PySimpleGUIで表示したウィンドウを閉じてもプロセスが残る

Last updated at Posted at 2023-05-12

【事象】
PySimpleGUIでウィンドウを表示するプログラムをPyInstallerでexe化しました。
そのexeを実行したあと、ウィンドウを閉じても
タスクマネージャーにプロセスが残ります。

なお、このプログラムはスレッド処理を使用しています。

【解決方法】
ウィンドウクローズを検知したあと、
メインスレッド以外のスレッドを明示的に終了させます。

for thread in threading.enumerate():
    if thread != threading.main_thread():
      ctypes.pythonapi.PyThreadState_SetAsyncExc(thread.native_id, ctypes.py_object(SystemExit))

参考サイト
https://zenn.dev/bluesilvercat/articles/c492339d1cd20c

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