简体   繁体   中英

Python - Cannot terminate console script without taskkill /F

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.

I'm not sure if this does a 'clean' termination of the process, but I found using the /T option for taskkill ensured that all parent and child processes are terminated as well which at least stopped the process.

Ultimately, the command becomes:

taskkill /T /F /PID <pid_number>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM