Open tscizzlebg opened 4 years ago
You can catch KeyboardInterrupt
exception (ctrl+c) with the try
clause. You can do cleanup in the finally
clause and call cef.Shutdown
there.
Otherwise it's an issue in upstream Chromium/CEF. If you kill parent process then other spawned processes don't exit on Windows by default.
You could use the psutil
python library to kill any hanging processes from previous runs. See https://pypi.org/project/psutil/ . Or simply os.system("taskkill /im subprocess.exe")
. But note that "subprocess.exe" is not a unique and may be a process from other app. You can rename the subprocess executable when distributing your app.
Thanks for the response.
Regarding renaming the subprocess.exe so that it's unique and thus safe to kill, I see multiple files dealing with the name "subprocess.exe" (tools/build.py
, tools/build_distrib.py
, tools/common.py
).
How would one change "subprocess.exe" -> "arbitrary_name_785lala.exe", not only for a built/distributed app, but for during development as well?
(Perhaps in the future this could be a parameter an app developer can set, like cefpython.SetSubprocessName("arbitrary_name_785lala")
)
You can rename the subprocess executable in the cefpython3 package (after installation) on developer machine. When distributing app and also when running on dev machine you can specify path to the subprocess executable (make it absolute path) via the ApplicationSettings.browser_subprocess_path
option passed to cef.Initialize
, see: https://github.com/cztomczak/cefpython/blob/master/api/ApplicationSettings.md#browser_subprocess_path .
The wx example in this repo is a good example (https://github.com/cztomczak/cefpython/blob/master/examples/wxpython.py).
On Windows 10, running the example, Ctrl-C, run it, Ctrl-C, etc. eventually in the Task Manager I get a subprocess.exe which runs indefinitely and consumes >20% CPU. More build up if this process is repeated.
Below I linked my question about this on StackOverflow, and a relevant discussion on CEF (not cefpython specifically).
https://stackoverflow.com/questions/60552567/orphaned-subprocesses-after-shutting-down-cefpython-despite-cleanup https://magpcss.org/ceforum/viewtopic.php?f=6&t=15817