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.