Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WindowsError: [Error 5] Access is denied

Tags:

python

I've been trying to kill a process but all my options give me a Windows Access Denied Error. I open the process(a python script) through test= subprocess.Popen([sys.executable, "testsc.py"]) and I want to kill that process.

So far, I've tried os.kill(pid, signal.SIGILL) , os.kill(pid, 9), test.Terminate() and simply test.kill(). All of these give me the error.

I am using Python 2.7.1.4 on a Windows 7 x86 machine. I would appreciate the help! Thanks!

like image 651
dawnoflife Avatar asked Jul 14 '11 05:07

dawnoflife


1 Answers

A workaround if anyone interested - even as an admin I get access denied on some services when using os.kill. however, this works:

import subprocess
subprocess.check_output("Taskkill /PID %d /F" % pid)

So if you don't care about being cross-platform and want a quick and dirty solution - try this instead.

like image 146
Ronen Ness Avatar answered Oct 07 '22 17:10

Ronen Ness