gpt4 book ai didi

python - psutil.AccessDenied : psutil. AccessDenied (pid=7868)

转载 作者:行者123 更新时间:2023-12-05 08:06:08 31 4
gpt4 key购买 nike

我正在尝试使用 psutil 终止进程 (zoom.exe)。但是,我收到错误 psutil.AccessDenied。我拥有执行此操作的所有权限,并且已经在另一台电脑上进行了测试。

代码

def kill_process(PROCNAME):
for proc in psutil.process_iter():
if proc.name() == PROCNAME:
proc.kill()
print(f'{PROCNAME} was succesfully killed')
time.sleep(3)

回溯

Traceback (most recent call last):
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_c
ret = self._cache[fun]
AttributeError: _cache

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_p
return fun(self, *args, **kwargs)
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_c
return fun(self)
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_p
exe = cext.proc_exe(self.pid)
PermissionError: [WinError 24] The program issued a command but the command length is incorrect.
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:/Users/Acer/Desktop/autozoom/autozoom.py", line 211, in <module>
kill_process('Zoom.exe')
File "c:/Users/Acer/Desktop/autozoom/autozoom.py", line 25, in kill_process
if proc.name() == PROCNAME:
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\__init__.py", line 630, in name
name = self._proc.name()
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 750, in name
return os.path.basename(self.exe())
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 681, in wrapper
raise convert_oserror(err, pid=self.pid, name=self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=7868)

最佳答案

解决了这段代码的问题:

def kill_process(PROCNAME):
for proc in psutil.process_iter():
try:
if proc.name().lower() == PROCNAME.lower():
proc.kill()
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
return False

关于python - psutil.AccessDenied : psutil. AccessDenied (pid=7868),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62334530/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com