в данном коде определенный процесс , если начинает нагружать процессор, в течении некоторого времени, его убиваем, вопрос : если процесс завершился, то почему начинает жрать ресурсы сам скрипт?
''' config.ini [connect] process = iron.exe cpu = 75 ''' import time import psutil import win32com.client import subprocess wmi=win32com.client.GetObject('winmgmts:') def loadConfig(): import ConfigParser config = ConfigParser.ConfigParser() config.read('config.ini') process = config.get('connect', 'process') cpu = config.get('connect', 'cpu') return {'process':process,'cpu':cpu} config = loadConfig() print config['process'] proc_n = config['process'] numb = int(config['cpu']) while True: for p in wmi.InstancesOf('win32_process'): try: res = p.Properties_('ProcessId') f = psutil.Process(int(res)) if p.Name == proc_n: print p.Name,res , f.get_cpu_percent() if f.get_cpu_percent() > numb: time.sleep(2) if f.get_cpu_percent() > numb: subprocess.Popen('taskkill /PID %d /T /f' % int(res), shell = True) #print p.Name, p.Properties_('ProcessId') except Exception as e: print e.message