Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108639

intermittent ValueErrors from subprocess

From Pavlos Parissis <pavlos.parissis@gmail.com>
Newsgroups comp.lang.python
Subject intermittent ValueErrors from subprocess
Date 2016-05-15 17:49 +0200
Message-ID <mailman.32.1463327394.2226.python-list@python.org> (permalink)
References <57389A9D.1010205@gmail.com>

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Hi,

I get intermittent ValueErrors[1] from subprocess when I check if an IP
is assigned to loopback interface by running:

/sbin/ip address show dev lo to 10.52.12.2/32

I use subprocess.check_output like this:

cmd = [
    '/sbin/ip',
    'address',
    'show',
    'dev',
    "{}".format(self.config['interface']),
    'to',
    "{}".format(self.config['ip_prefix']),
]

try:
    out = subprocess.check_output(
        cmd,
        universal_newlines=True,
        timeout=1)
except subprocess.CalledProcessError as error:
    return True
except subprocess.TimeoutExpired:
    return True
else:
    if self.config['ip_prefix'] in out:
        return True
    else:
        return False


and I get the following exception:

ValueError: Invalid file object: <_io.TextIOWrapper name=11
encoding='UTF-8'>

As a consequence of the raised exception thread dies and I now catch
ValueError in the same try block in order to avoid the crash.

It has happened ~5 times and this code is executed from multiple
threads and every ~10secs on several(~40) systems for more than
18months. So, it is quite impossible for me to reproduce it.
It could be that the system returns corrupted data or python fails for
some unknown reason to parse the output.

The program uses Python 3.4.4 and runs on Debian stable and CentOS 6/7.

The full code path in question can be found here:
https://github.com/unixsurfer/anycast_healthchecker/blob/master/anycast_healthchecker/servicecheck.py#L90

I did a search on bugs.python.org about it but I didn't find anything.

Has anyone seen this behavior before?

Cheers,
Pavlos

[1] https://gist.github.com/unixsurfer/67db620d87f667423f6f6e3a04e0bff5

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

intermittent ValueErrors from subprocess Pavlos Parissis <pavlos.parissis@gmail.com> - 2016-05-15 17:49 +0200

csiph-web