[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3] iotests: Test NBD client reconnection
From: |
Roman Kagan |
Subject: |
Re: [PATCH v3] iotests: Test NBD client reconnection |
Date: |
Mon, 11 Nov 2019 09:48:25 +0000 |
User-agent: |
Mutt/1.12.1 (2019-06-15) |
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.