Python Resource Library Resource Limit Functions

Python Resource Library Resource Limit Functions

Resource Library Python:

This module in python provides basic mechanisms for measuring and controlling system resources utilized by a program. And the symbolic constants are used to specify particular system resources and to request usage information about either the current process or its children. If there is a syscall failure, the OSError is raised.

Resource Limit:

The functions defined here are related to the limits assigned to the resources. Resource limits can be set for individual processes and the processes they start i.e. their child processes. These limits are hard and soft limits. So what are soft limits and hard limits?
There are 2 types of resource limits set by 'ulimit' command: hard limits and soft limits
The soft limits are the ones that actually affect processes and hard limits are the maximum values for soft limits. Any user or process can raise the soft limits up to the value of the hard limits. If the hard limits needs to be changed, it can only be done by the processes with superuser authority.


This function in python resource library returns a tuple with the current soft and hard limits of the resources as (soft limits, hard limits). It returns the ValueError if the resource provided as the argument is invalid. It returns an error if the system call fails unexpectedly.


resource.setrlimit(resource, limits):

This function in the python library resource sets the new limits of consumption of resource. It sends the limits to the function in the form of a tuple as (soft limits, hard limits) which contains two integers describing the new limits. A value RLIM_INFINITY can be used to request a limits that is unlimited. 

It raises a ValueError if an invalid resource is specified as the argument and passed to the function, or if the soft limit exceeds the hard limit value (like if you specify the soft limit as RLIM_INFINITY but the hard limits is not specified as unlimited then ValueError is raised). A process with effective UID(Unique Identifier) of the super user can request any valid limit value, including unlimited, within the system imposed limit, otherwise ValueError will be raised if the requested limit exceeds the system imposed limit. 
It raises error if the underlying system call fails.

resource.prlimit(pid, resource[;limits]):

This function in the resource library of python combines the setrlimit() and getrlimit() functions in single function and supports to get and set the resource limits of a arbitrary. If pid(Process ID) is 0, then the call applies to the current process. resource and limits have the same meaning as in setrlimit(), except that limits is optional. 
When limits is not given the function returns the resource limit of the process pid. When limits is given the resource limit of the process is set and the former resource limit is returned. 
It raises ProcessLookupError when pid can’t be found and PermissionError when the user doesn’t have CAP_SYS_RESOURCE for the process.



More Articles of Arkaja Sharan:

Name Views Likes
Python codecs Library Error Handling schemes module functions 77 0
Python codecs Library Error Handler register_error and lookup_error functions 71 0
Python codecs Library Error Handlers 77 0
Python codecs Library open and EncodedFile functions 66 0
Python codecs Library iterencode and iterdecode functions 85 0
Python codecs Library register and unregister functions 67 0
Python codecs Library getreader and getwriter functions 79 0
Python codecs Library getincrementalencoder and getincrementaldecoder 65 0
Python codecs Library getencoder and getdecoder functions 70 0
Python Introduction to codecs Library 100 0
Python fcntl Library flock and lockf functions 78 0
Python fcntl Library fcntl and ioctl functions 90 0
Python Resource Library resource usage functions 90 0
Python Resource Library resource usage symbolic constants 73 0
Python Resource Library Resource Limit Functions 88 0
Python resource library resource limit symbolic constants 80 0
Python Introduction to Resource Library 70 0
Python stringprep Library in_table_d1 and in_table_d2 functions 78 0
Python stringprep Library in_table_c8 and in_table_c9 functions 81 0
Python stringprep Library in_table_c5 in_table_c6 and in_table_c7 functions 70 0
Python stringprep Library in_table_c3 and in_table_c4 functions 75 0
Python stringprep library in_table_c21 in_table_c22 and in_table_c21_c22 77 0
Python stringprep library functions in_table_c11 in_table_c12 and in_table_c11_c12 78 0
Python Introduction to stringprep Library 79 0
Python unicodedata library is_normalized unidata_version and ucd_3_2_0 75 0
Python Unicodedata Library functions normalize and decomposition 130 0
Python Unicodedata Library functions east_asian_width and mirrored 82 1
Python Unicodedata Library category bidirectional and combining functions 114 0
Introduction to Unicodedata library lookup and name functions 79 0
Unicode Library decimal digit and numeric functions 82 0
Introduction to Unicode Data library 0 0