5

I have searched it over internet but found nothing related to it.

I have two large python dictionaries that contains more than 2 Million key value pairs .My computer is continuously showing 100% utilization when I am doing any kind of computation on this data.

Due to this I am not able to perform other task on my system as it hangs frequently.

Is there any way that can restrict the maximum CPU allocation for a python program by writing some code in the python program itself.As I do not want to allow this program to use 100% cpu time.

PS: I am currently using sleep function to restrict it but it looks silly.I am using windows 7.

  • 4
    CPU time not used is CPU time wasted; unless the problem is to avoid overheating in badly assembled computers, the solution isn't to lower the CPU utilization, but to lower the priority of your process, so if there's any other task competing for the CPU your process will always "lose", thus leaving the system responsive. – Matteo Italia May 28 '13 at 02:24
  • Also, see: http://stackoverflow.com/questions/1023038/change-process-priority-in-python-cross-platform – Matteo Italia May 28 '13 at 02:27
  • @MatteoItalia That question is about unix/linux platform .As I am a windows7 user so looking something for windows .Thanks for reference . –  May 28 '13 at 02:30
  • Nope, that question is about a cross-platform way; scroll below, there are solutions both for Windows and for Linux. – Matteo Italia May 28 '13 at 02:34
  • In this SetPriority (p) method they have given 4 different priority for the process .Is there any doc available that can tell me that how the resource allocation has been made for these priorities. –  May 28 '13 at 02:43

1 Answers1

5

If you are on a linux/unix platform you can use nice to reduce the priority of your process.

This only helps if it is cpu that is maxed out. If you are waiting on disk/swap I/O for example, nice really won't help.

NICE(1)                          User Commands                         NICE(1)

NAME
       nice - run a program with modified scheduling priority

SYNOPSIS
       nice [OPTION] [COMMAND [ARG]...]

DESCRIPTION
       Run  COMMAND  with an adjusted niceness, which affects process schedul‐
       ing.  With no COMMAND, print the current  niceness.   Nicenesses  range
       from -20 (most favorable scheduling) to 19 (least favorable).

For Windows try the START command

Community
  • 1
  • 1
John La Rooy
  • 295,403
  • 53
  • 369
  • 502