I have a python application which is installed as a console_script on Windows.
I'd like the application to run as a background process for some time and then I would like to terminate it.
I start the process with:
START /B <application_name>
And try to terminate it with:
taskkill /PID <PID>
However when I try and terminate the process, without the force option, I get the error:
ERROR: The process with PID 17836 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
Does anyone know how I should extend my Python application so that it can be terminated without the force option?
Not sure if it is important, but I noticed that starting the application actually creates two processes, a python.exe process which seems to be the parent process and the application process.
WM_CLOSEto the top-level and message-only windows owned by a process. (Support for closing message-only windows might only be in Windows 10.) Only one console application is considered the effective owner of the console window, which is initially the process that allocates the console. (Omit the/Boption ofstartto have your program allocate a new console.) That's not a reliable state. Instead, you can host a message-only or top-level invisible window that handlesWM_CLOSEby initiating a graceful exit.