From 2edded6301fb530c1bf1df197f4ad77437e71623 Mon Sep 17 00:00:00 2001 From: Akashdeep Dhar Date: Nov 29 2021 05:42:06 +0000 Subject: Handle exception for non-existent processes Moved out process controllers to a separate modules Signed-off-by: Akashdeep Dhar --- diff --git a/obserware/readers/procwind/controller.py b/obserware/readers/procwind/controller.py new file mode 100644 index 0000000..5365f19 --- /dev/null +++ b/obserware/readers/procwind/controller.py @@ -0,0 +1,64 @@ +""" +Obserware +Copyright (C) 2021 Akashdeep Dhar + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + + +import psutil + + +def kill_process(prociden): + try: + psutil.Process(prociden).kill() + except psutil.NoSuchProcess: + pass + except psutil.PermissionError: + pass + except psutil.AccessDenied: + pass + + +def terminate_process(prociden): + try: + psutil.Process(prociden).terminate() + except psutil.NoSuchProcess: + pass + except psutil.PermissionError: + pass + except psutil.AccessDenied: + pass + + +def resume_process(prociden): + try: + psutil.Process(prociden).resume() + except psutil.NoSuchProcess: + pass + except psutil.PermissionError: + pass + except psutil.AccessDenied: + pass + + +def suspend_process(prociden): + try: + psutil.Process(prociden).suspend() + except psutil.NoSuchProcess: + pass + except psutil.PermissionError: + pass + except psutil.AccessDenied: + pass diff --git a/obserware/readers/procwind/provider.py b/obserware/readers/procwind/provider.py index 220d185..5528f49 100644 --- a/obserware/readers/procwind/provider.py +++ b/obserware/readers/procwind/provider.py @@ -50,39 +50,3 @@ def return_mainscreen_onetimed_statistics(prociden): ), } return retndata - - -def kill_process(prociden): - try: - psutil.Process(prociden).kill() - except psutil.PermissionError: - pass - except psutil.AccessDenied: - pass - - -def terminate_process(prociden): - try: - psutil.Process(prociden).terminate() - except psutil.PermissionError: - pass - except psutil.AccessDenied: - pass - - -def resume_process(prociden): - try: - psutil.Process(prociden).resume() - except psutil.PermissionError: - pass - except psutil.AccessDenied: - pass - - -def suspend_process(prociden): - try: - psutil.Process(prociden).suspend() - except psutil.PermissionError: - pass - except psutil.AccessDenied: - pass