Я получаю сообщение об ошибке при запуске следующего кода:
from win32gui import GetForegroundWindow
import psutil
import time
import win32process
process_time = {}
timestamp = {}
while True:
current_app =
psutil.Process(win32process.GetWindowThreadProcessId(GetForegroundWindow())[1]).name().replace(".exe", "")
timestamp[current_app] = int(time.time())
time.sleep(1)
if current_app not in process_time.keys():
process_time[current_app] = 0
process_time[current_app] = process_time[current_app]+int(time.time())-timestamp[current_app]
print(process_time)
Ошибка:
Traceback (most recent call last):
File "C:\Users\raaji\PycharmProjects\HELLO WORLD\venv\lib\site-packages\psutil\_pswindows.py", line 679, in wrapper
return fun(self, *args, **kwargs)
File "C:\Users\raaji\PycharmProjects\HELLO WORLD\venv\lib\site-packages\psutil\_pswindows.py", line 933, in create_time
user, system, created = cext.proc_times(self.pid)
ProcessLookupError: [Errno 3] No such process (originated from OpenProcess)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\raaji\PycharmProjects\HELLO WORLD\venv\lib\site-packages\psutil\__init__.py", line 373, in _init
self.create_time()
File "C:\Users\raaji\PycharmProjects\HELLO WORLD\venv\lib\site-packages\psutil\__init__.py", line 723, in create_time
self._create_time = self._proc.create_time()
File "C:\Users\raaji\PycharmProjects\HELLO WORLD\venv\lib\site-packages\psutil\_pswindows.py", line 681, in wrapper
raise convert_oserror(err, pid=self.pid, name=self._name)
psutil.NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=29069632)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Public/Time Engine/APP TRACKER(TEST).py", line 14, in <module>
current_app = psutil.Process(win32process.GetWindowThreadProcessId(GetForegroundWindow())[1]).name().replace(".exe", "")
File "C:\Users\raaji\PycharmProjects\HELLO WORLD\venv\lib\site-packages\psutil\__init__.py", line 346, in __init__
self._init(pid)
File "C:\Users\raaji\PycharmProjects\HELLO WORLD\venv\lib\site-packages\psutil\__init__.py", line 386, in _init
raise NoSuchProcess(pid, None, msg)
psutil.NoSuchProcess: psutil.NoSuchProcess no process found with pid 29069632