Terminate subprocess in Windows, access denied

孤人 提交于 2019-12-18 04:51:14

问题


-

import time
import subprocess
from os.path import expanduser

chrome_path = expanduser('~\Local Settings\Application Data\Google\Chrome\Application\chrome.exe')

proc = subprocess.Popen(chrome_path)
time.sleep(4)
proc.terminate()

Output: WindowsError: [Error 5] Access is denied

How can I kill the Chrome process?

Python 2.6 on Windows XP.


回答1:


what happens if you use TASKKILL /F /PID [number of process ID] ? Give it a try. Launch it through import OS




回答2:


I don't know about Windows, but have noticed on Linux that Google Chrome "protects" itself from operating system control signals in a way that few programs do:

$ ps -lp 2345
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S  1000  2345     1  0  80   0 - 17699 skb_re ?        00:00:00 chrome
$ kill -TERM 2345
$ kill -HUP 2345
$ kill -SEGV 2345
$ ps -lp 2345
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S  1000  2345     1  0  80   0 - 17699 skb_re ?        00:00:00 chrome

I suspect this may be the root cause of your troubles. Incidentally, I'm posting this note from process 2345.




回答3:


I think the best bet is to find and close the window at the os level: http://python.net/crew/skippy/win32/Downloads.html.



来源:https://stackoverflow.com/questions/2868129/terminate-subprocess-in-windows-access-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!