Is it possible to limit the consumption of resources so that the equipment is not left unused?

2

Sometimes my scripts require a lot of resources and the equipment is left unused. I would like to know how to limit the access of my scripts to the resources of the computer. For example, do not let him use more than 50%.

I use the interpreter Spyder. But I have not found any options in the configuration.

The OS is Windows 7

    
asked by Zhisi 30.01.2018 в 11:22
source

3 answers

0

Here is a mini example of the idea I told you about the other day. The renice command in linux allows you to assign the priority of a process.

#!/usr/bin/env python3

import os
import subprocess
import time

def main():
    process_pid = os.getpid()

    return_code = subprocess.call("renice -n -19 " + str(process_pid), shell=True)

    if return_code != 0:
        print("Error no pude cambiar la prioridad de " + str(process_pid))

    print("Proceso " + str(process_pid))

    start_time = time.time()
    stop_time = start_time  + 30 # 30 segundos

    while True:
        if (time.time()) >= stop_time:
            print("Paramos")
            break

    print("FIN")



if __name__ == "__main__":
    main()
    
answered by 31.01.2018 в 12:31
0

Without knowing the code of the scripts that you run, it is difficult to help. However, you could incorporate python generators (if you have not done so) because they substantially improve performance. In this link there is an explanation and example of generator: link

I leave an example code in case it could be useful:

def generador():
    for i in range(10):
        yield int(i)


def principal():
    for num in generador():
        number=num+10
        print (number)

if __name__ == "__main__":
    principal()
    
answered by 03.02.2018 в 01:42
-1

You can reduce the priority of the process in the task manager:

Ctrl + Shift + Esc > Process tab > Right click > Set priority.

You can try "Low" or "Below normal" and see if it improves the response of the system.

    
answered by 31.01.2018 в 11:55