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


Groups > comp.lang.python > #108647

Re: intermittent ValueErrors from subprocess

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: intermittent ValueErrors from subprocess
Date Mon, 16 May 2016 08:08:09 +1000
Lines 46
Message-ID <mailman.4.1463350097.19823.python-list@python.org> (permalink)
References <57389A9D.1010205@gmail.com> <CAPTjJmp1H99HKmEarskE1b-ia0=KFDBTpfU+cWt6vVFeJtBHZg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de j0VpK95mJS4lBCmCLj2K/Af1UPWwZ11lvrlEwnNZx0LQ==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '16,': 0.03; 'cpython': 0.05; 'error:': 0.05; 'converts': 0.07; 'valueerror:': 0.07; 'cc:addr:python-list': 0.09; 'cmd': 0.09; 'exception:': 0.09; 'exception': 0.13; "'to',": 0.16; '2016': 0.16; 'cmd,': 0.16; 'descriptor.': 0.16; 'descriptors,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'string,': 0.18; 'try:': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'skip:" 30': 0.20; 'problem:': 0.22; 'am,': 0.23; '(you': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; 'skip:u 20': 0.28; 'there.': 0.30; 'file': 0.34; 'except': 0.34; 'running': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'false': 0.35; 'nothing.': 0.35; 'received:74.125.82': 0.35; 'possible': 0.36; 'subject:: ': 0.37; 'sources': 0.37; 'does': 0.39; 'subject:from': 0.39; 'unable': 0.39; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'chrisa': 0.84; 'object:': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=qLPeR+qCNVhfObCsgi0PKVHO1WM7wnRcIbNL//Ydy30=; b=BmnNdoizQVN1bb/fPV1ceKhWpAYaL+6Idp5jv5D32WJR10IL0NHMoVua3jV79rPM4s Pu2U90eoZyRCOwR+ib7JnF8NbjYXRo/RunZL050zi+ILF6fh721mGqI9su7nwvJIJ/Ue OvKEOtI/QQekt/ZjtF4maCpBWsRT0hn/IeGPQ9IwkjbxgT7rNyXlsPl2JaOLkZv/fsM7 Kyx9aQ/QrnXEokrlzg9HIgffycFbfQvO2uozMiYkzR5z8McrbOasrc2O/VABYBkZ7FBa p/Cm7YSURVwnXW58qTi7ZsxWXA0whK9s9bF66hgBklsA2tZH5w6GewnfMS/38SGUtQ/P v3bw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=qLPeR+qCNVhfObCsgi0PKVHO1WM7wnRcIbNL//Ydy30=; b=NH4lx620BEFS9GVbNLgB5oAv0O8f4EZuG9N4jrScOwCpoMHF1QbazJjytN1BvqKTbt Qxnaarc4O3OXo/rGLfcgM6/QQpAuyHl0lBR/Gq045wMaAMYdIFwZF8GQQ8KgEByiWee6 8MlN843KnjaCkb43WJlGOVV5tGdStH6kYWhKB+E6SZRJ8qd6mpHMNU8Cq7rhy6qVmIjZ WKH9R9o6ralwT2xU9ewjLP4zve/vlcBtRK76P0KkCbnwc8+E7IySsLIaXLB2X/oD+1mI PdhPeB+YFznQQm36Rr7BhhOc7+5Pb6tgRqcpTr/Gcs0kGu4Cw2eeDKH/kRD6Hz7vRq0+ yzDQ==
X-Gm-Message-State AOPr4FUPbKX+sueYZqpCwOemk+pqIkD0RUZjbewT2NHEHEbmdmoVx8leaMudma27brtunsrQCvhbCNkxKvwqDg==
X-Received by 10.194.186.237 with SMTP id fn13mr27341006wjc.47.1463350089266; Sun, 15 May 2016 15:08:09 -0700 (PDT)
In-Reply-To <57389A9D.1010205@gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAPTjJmp1H99HKmEarskE1b-ia0=KFDBTpfU+cWt6vVFeJtBHZg@mail.gmail.com>
X-Mailman-Original-References <57389A9D.1010205@gmail.com>
Xref csiph.com comp.lang.python:108647

Show key headers only | View raw


On Mon, May 16, 2016 at 1:49 AM, Pavlos Parissis
<pavlos.parissis@gmail.com> wrote:
> I use subprocess.check_output like this:
>
> cmd = [
>     '/sbin/ip',
>     'address',
>     'show',
>     'dev',
>     "{}".format(self.config['interface']),
>     'to',
>     "{}".format(self.config['ip_prefix']),
> ]

Unrelated to your problem: "{}".format(x) is the same as str(x), and
if x is already a string, it does exactly nothing. Most likely you can
just put your configs straight in there.

> 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'>

Searching the CPython sources for that exception shows one hit:
selectors.py, where it converts a file object to an integer file
descriptor. (You could have helped out by showing us the full
traceback.) Is it possible you were running out of file descriptors,
or in some other way unable to create the pipe?

ChrisA

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


Thread

Re: intermittent ValueErrors from subprocess Chris Angelico <rosuav@gmail.com> - 2016-05-16 08:08 +1000

csiph-web