所以基本上我已经在使用Psutil的python中创建了这个应用程序。我用它来以非常高的速度暂停和恢复一个过程。虽然它确实适用于大多数过程,但它对某些人来说并不起作用。我会在下面提供错误代码,但如果你决定帮忙请非常友好,我刚刚开始使用python
import psutil
import time
import subprocess
print("Auto Suspender")
condition = 10
subprocess.call("taskkill /Program example")
print("Program Example has been killed :)")
time.sleep(1)
somepid = int(input("What is Process ID ?"))
p = psutil.Process(somepid)
print("Working...")
time.sleep(0.5)
while condition == 10:
choice = input("1__Suspend")
if (choice == "1"):
while condition == 10:
p.suspend()
print("Suspended !")
time.sleep(0.1)
p.resume
print("Resumed !")
else:
print("Invalid response")`enter code here`
错误Iam
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 207, in wrapper
return fun(self, *args, **kwargs)
File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 366, in suspend
return cext.proc_suspend(self.pid)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Jacob/PycharmProjects/Suspender.111/Main.py", line 26, in <module>
p.suspend()
File "C:\Python34\lib\site-packages\psutil\__init__.py", line 273, in wrapper
return fun(self, *args, **kwargs)
File "C:\Python34\lib\site-packages\psutil\__init__.py", line 1025, in suspend
self._proc.suspend()
File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 213, in wrapper
raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: (pid=3076)
Process finished with exit code 1
答案 0 :(得分:1)
我认为您没有足够的权限进行流程挂起。 Windows操作系统(以及其他操作系统中)中的某些进程在另一个用户帐户下运行,在Windows中通常位于系统帐户下,普通用户无法挂起或终止此进程。尝试以管理员用户身份运行脚本,脚本可能会正常工作。