Psutil in the Rlimit method in Rhel6 escalation error attributeerror: ' Process ' object has no attribute ' rlimit '

Source: Internet
Author: User
Problem Description

The Rlimit method using Psutil on centos6.5 reported the following error

>>> import psutil
>>> p=psutil. Process ()
>>> p.rlimit (psutil. RLIMIT_CPU)
Traceback (most recent):
  File "<stdin>", line 1, in <module>
Attributeerror: ' Process ' object has no attribute ' rlimit '
problem Reason

First check the Psutil version, is the latest version 4.1.0, the Rlimit function should already be included in the library, so the library version is excluded too low issue.

And then see a description in the {path_to_python}/site-packages/psutil/tests/test_linux.py file that explains the problem well, see the code snippet below

    @unittest. Skipunless (
        get_kernel_version () >= (2, 6,),
        "Prlimit () Not available on" Linux kernel Versio N ")
    def test_prlimit_availability (self):
        # Prlimit () should is available starting from kernel 2.6.36
        p = Psut Il. Process (Os.getpid ())
        P.rlimit (psutil. Rlimit_nofile)
        # if Prlimit () is supported *at least* this constants should
        

Note that the Rlimit function is available only in Linux kernel 2.6.36 and above, so decisively view the system kernel version

$ uname-a
Linux fanbinlinux 2.6.32-573.22.1.el6.x86_64 #1 SMP Wed Mar 03:35:39 UTC 2016 x86_64 x86_64 x86_64 Inux

The original is 2.6.32, OK, life back, but finally found the cause of the problem. Solutions Upgrade Kernel

Oh, this is to tease you to play the solution, many situations users can not allow you to upgrade the kernel, of course, if allowed, this is the simplest solution. Swap Resource Library

Looking at the official Python documentation and discovering that the Getrlimit and Setrlimit methods can be implemented using the standard library resource, the difference between resource library and Psutil library is that the resource library can only set or query Rlimit for the current process. And Psutil can be targeted at any process.

The following is the use of the resource library

Import Resource
Resource.getrlimit (resource. RLIMIT_CPU)
Resource.setrlimit (Resource). RLIMIT_CPU, XXX)

Reference https://docs.python.org/2/library/resource.html

Reprint please indicate this address in the form of link
This article address: http://blog.csdn.net/kongxx/article/details/51189373

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.