qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Roman Kagan <rkagan@virtuozzo.com>
To: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Cc: "kwolf@redhat.com" <kwolf@redhat.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	Denis Lunev <den@virtuozzo.com>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"mreitz@redhat.com" <mreitz@redhat.com>
Subject: Re: [PATCH v3] iotests: Test NBD client reconnection
Date: Mon, 11 Nov 2019 09:48:25 +0000	[thread overview]
Message-ID: <20191111094822.GA126513@rkaganb.sw.ru> (raw)
In-Reply-To: <55df73cb-ffe8-e4c6-b97a-346bdf28f1e2@virtuozzo.com>

On Mon, Nov 11, 2019 at 12:18:48PM +0300, Andrey Shinkevich wrote:
> 
> 
> On 08/11/2019 17:05, Roman Kagan wrote:
> > On Fri, Nov 08, 2019 at 01:49:50PM +0000, Vladimir Sementsov-Ogievskiy wrote:
> >> 01.11.2019 19:54, Andrey Shinkevich wrote:
> >>> +def check_proc_NBD(proc, connector):
> >>> +    try:
> >>> +        exitcode = proc.wait(timeout=10)
> >>> +
> >>> +        if exitcode < 0:
> >>> +            log('NBD {}: EXIT SIGNAL {}\n'.format(connector, -exitcode))
> >>> +            log(proc.communicate()[0])
> >>> +        else:
> >>> +            line = proc.stdout.readline()
> >>
> >>
> >> could we use proc.communicate() for both cases, what is the difference?
> > 
> > In fact if proc produces any non-trivial amount of output you are better
> > off using .communicate() otherwise your child may block on output and
> > never exit.  See
> > https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
> > for how to express the above logic correctly.  The exit code *after*
> > .communicate is available in .returncode.
> > 
> 
> The pattern by the link above does not work (Python3):
> 
> proc = subprocess.Popen(...)
> try:
>      outs, errs = proc.communicate(timeout=15)
> except TimeoutExpired:
>      proc.kill()
>      outs, errs = proc.communicate()
> 
> as 'proc' cannot be used for output after being killed. It results in 
> another exception being raised.

Of course it can't.  You need to use the strings returned by
.communicate().

Roman.


  reply	other threads:[~2019-11-11  9:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-01 16:54 [PATCH v3] iotests: Test NBD client reconnection Andrey Shinkevich
2019-11-08 13:49 ` Vladimir Sementsov-Ogievskiy
2019-11-08 14:05   ` Roman Kagan
2019-11-11  9:18     ` Andrey Shinkevich
2019-11-11  9:48       ` Roman Kagan [this message]
2019-11-11  9:07   ` Andrey Shinkevich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191111094822.GA126513@rkaganb.sw.ru \
    --to=rkagan@virtuozzo.com \
    --cc=andrey.shinkevich@virtuozzo.com \
    --cc=den@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).