qemu-block
[Top][All Lists]
Advanced

[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: Fri, 8 Nov 2019 14:05:31 +0000
User-agent: Mutt/1.12.1 (2019-06-15)

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.

> 
> > +            log('NBD {}: {}'.format(connector, line.rstrip()))
> > +
> > +    except subprocess.TimeoutExpired:
> > +        proc.kill()
> > +        log('NBD {}: ERROR timeout expired'.format(connector))
> > +    finally:
> > +        if connector == 'server':
> > +            os.remove(nbd_sock)
> > +            os.remove(conf_file)

Roman.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]