Python Forum
psutil for monitor a software finish process and notification
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
psutil for monitor a software finish process and notification
#1
psutil for monitor a software finish process and notification

import psutil, time
PROCNAME = "monitor.exe"

for proc in psutil.process_iter():
    if proc.name() == PROCNAME:
        print(proc.pid)
        softwarepid=proc.pid
        time.sleep(0.1)
        pi = psutil.Process(softwarepid)
        softwarepercent = pi.cpu_percent(interval=1.0)
        print(softwarepercent)
Error:
Traceback (most recent call last): File "C:\Users\xx\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_common.py", line 449, in wrapper ret = self._cache[fun] AttributeError: _cache During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\xx\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 679, in wrapper return fun(self, *args, **kwargs) File "C:\Users\xx\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_common.py", line 452, in wrapper return fun(self) File "C:\Users\xx\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 766, in exe exe = cext.proc_exe(self.pid) PermissionError: [WinError 24] The program issued a command but the command length is incorrect: '(originated from NtQuerySystemInformation)' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/xx/PycharmProjects/app/bee.py", line 29, in <module> if proc.name() == PROCNAME: File "C:\Users\xx\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\__init__.py", line 630, in name name = self._proc.name() File "C:\Users\xx\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\xx\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=2928)
same code test in different pc, same version pycharm and win. some can get result and error. some can't get result and give same error. what's wrong with it why can't get result? and get CPU percent function seems no right way.

my idea: as this software don't have notification function. so i want to make python monitor it. monitor it CPU usage, when it stop working. it will stay in 0.0% then send email and sounds notification. i am no sure it's the right way. please advice.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sound Sensor With EMail Notification parascand 1 440 Dec-10-2023, 03:10 AM
Last Post: deanhystad
  Error notification after encoding robertje1024 1 1,163 May-29-2022, 04:18 PM
Last Post: Axel_Erfurt
  Is it possible to make a program recognize how many clicks it has had on the monitor? jao 0 1,130 Feb-25-2022, 06:31 PM
Last Post: jao
  How to make scraper send email notification just once themech25 0 1,362 Nov-08-2021, 01:51 PM
Last Post: themech25
  Can't read virtual pin or use notification on blynk flypon 1 3,090 Oct-28-2021, 02:32 PM
Last Post: ChanceTran
Sad SyntaxError: from simple python example file from mind-monitor code (muse 2) warmcupoftea 4 2,753 Jul-16-2021, 02:51 PM
Last Post: warmcupoftea
  running python script showing an icon in the tray notification area chubbychub 1 4,476 Nov-01-2020, 03:52 PM
Last Post: jefsummers
  Monitor specific line of code from website Olimpiarob 1 1,807 Jul-09-2020, 03:20 PM
Last Post: mrdominikku
  Python 3.9 alpha how to install psutil? lmh1 10 8,678 Apr-12-2020, 11:25 AM
Last Post: lmh1
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,620 Sep-03-2019, 09:49 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020