Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOError: [Errno 0] Error when calling proc.as_dict(attrs=['pid', 'environ']) #856

Closed
pwilczynskiclearcode opened this issue Jul 7, 2016 · 3 comments
Labels

Comments

@pwilczynskiclearcode
Copy link

pwilczynskiclearcode commented Jul 7, 2016

IOError: [Errno 0] Error was raised when calling proc.as_dict(attrs=['pid', 'environ'])

env/lib/python2.7/site-packages/mirakuru/base.py:224: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

env_name = 'mirakuru_uuid'
env_value = '19074:99420fe3-bbf0-4479-91d0-648ba4b35572'

    def processes_with_env_psutil(env_name, env_value):
        """
        Find PIDs of processes having environment variable matching given one.

        Internally it uses `psutil` library.

        :param str env_name: name of environment variable to be found
        :param str env_value: environment variable value prefix
        :return: process identifiers (PIDs) of processes that have certain
                 environment variable equal certain value
        :rtype: set
        """
        pids = set()

        for proc in psutil.process_iter():
            try:
>               pinfo = proc.as_dict(attrs=['pid', 'environ'])

env_name   = 'mirakuru_uuid'
env_value  = '19074:99420fe3-bbf0-4479-91d0-648ba4b35572'
penv       = {}
pids       = set([])
pinfo      = {'environ': {}, 'pid': 28289}
proc       = <psutil.Process(pid=28368, name='gunicorn') at 140211648444560>

env/lib/python2.7/site-packages/mirakuru/base_env.py:54: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <psutil.Process(pid=28368, name='gunicorn') at 140211648444560>
attrs = ['pid', 'environ'], ad_value = None

    def as_dict(self, attrs=None, ad_value=None):
        """Utility method returning process information as a
            hashable dictionary.

            If 'attrs' is specified it must be a list of strings
            reflecting available Process class' attribute names
            (e.g. ['cpu_times', 'name']) else all public (read
            only) attributes are assumed.

            'ad_value' is the value which gets assigned in case
            AccessDenied or ZombieProcess exception is raised when
            retrieving that particular process information.
            """
        excluded_names = set(
            ['send_signal', 'suspend', 'resume', 'terminate', 'kill', 'wait',
             'is_running', 'as_dict', 'parent', 'children', 'rlimit'])
        valid_names = _process_attrnames - excluded_names
        retdict = dict()
        ls = set(attrs) if attrs else _process_attrnames
        for name in ls:
            if name not in valid_names:
                continue
            try:
                attr = getattr(self, name)
                if callable(attr):
>                   ret = attr()

ad_value   = None
attr       = <bound method Process.environ of <psutil.Process(pid=28368, name='gunicorn') at 140211648444560>>
attrs      = ['pid', 'environ']
excluded_names = set(['as_dict', 'children', 'is_running', 'kill', 'parent', 'resume', ...])
ls         = set(['environ', 'pid'])
name       = 'environ'
retdict    = {}
self       = <psutil.Process(pid=28368, name='gunicorn') at 140211648444560>
valid_names = set(['cmdline', 'connections', 'cpu_affinity', 'cpu_percent', 'cpu_times', 'create_time', ...])

env/lib/python2.7/site-packages/psutil/__init__.py:473: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <psutil.Process(pid=28368, name='gunicorn') at 140211648444560>

    def environ(self):
        """The environment variables of the process as a dict.  Note: this
                might not reflect changes made after the process started.  """
>       return self._proc.environ()

self       = <psutil.Process(pid=28368, name='gunicorn') at 140211648444560>

env/lib/python2.7/site-packages/psutil/__init__.py:767: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <psutil._pslinux.Process object at 0x7f859189cc30>, args = ()
kwargs = {}, err = IOError(0, 'Error')

    @functools.wraps(fun)
    def wrapper(self, *args, **kwargs):
        try:
>           return fun(self, *args, **kwargs)

args       = ()
err        = IOError(0, 'Error')
fun        = <function environ at 0x7f85a42b1a28>
kwargs     = {}
self       = <psutil._pslinux.Process object at 0x7f859189cc30>

env/lib/python2.7/site-packages/psutil/_pslinux.py:962: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <psutil._pslinux.Process object at 0x7f859189cc30>

    @wrap_exceptions
    def environ(self):
        with open_text("%s/%s/environ" % (self._procfs_path, self.pid)) as f:
>           data = f.read()
E           IOError: [Errno 0] Error

f          = <closed file '/proc/28368/environ', mode 'rt' at 0x7f85914b94b0>
self       = <psutil._pslinux.Process object at 0x7f859189cc30>

env/lib/python2.7/site-packages/psutil/_pslinux.py:1053: IOError

environment:
python 2.7.11, psutil 4.3.0, happened during running a test suite in py.test 2.9.2

@giampaolo
Copy link
Owner

Hhmm... that looks like a Python bug. open(...).read() sets IOError with errno to 0. Weird.
For completeness open_text() here is just a 1:1 wrapper around open(), so nothing "special":

def open_text(fname, **kwargs):

Are you able to reproduce this issue when you want? If so, can you replicate it on Python 3?

@pwilczynskiclearcode
Copy link
Author

pwilczynskiclearcode commented Jul 7, 2016

Unfortunately it's a random failure.
Maybe it's not Python's fault by the old Debian Wheezy that I use

@giampaolo
Copy link
Owner

Yeah, unfortunately in case of errno = 0 there really isn't a sane decision that psutil can take regarding how to handle it: letting it propagate is the best compromise IMO.
And yeah, I agree this looks like a bug with the old Linux distro you're using.
Closing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants