From 4a6aacef992e1d5b78f9d80004936fb540740bf5 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 12 Oct 2017 14:51:19 +0100 Subject: [PATCH] Instrument/Acmecape: ensure iio-capture termination Once an ACME cape instrument is released, if the stop() method has not been called by the client code, let's ensure to release the channels by killing the corresponding iio-caputure process. Signed-off-by: Patrick Bellasi --- devlib/instrument/acmecape.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/devlib/instrument/acmecape.py b/devlib/instrument/acmecape.py index 818094f..5c10598 100644 --- a/devlib/instrument/acmecape.py +++ b/devlib/instrument/acmecape.py @@ -58,6 +58,12 @@ class AcmeCapeInstrument(Instrument): self.add_channel('device', 'current') self.add_channel('timestamp', 'time_ms') + def __del__(self): + if self.process and self.process.pid: + self.logger.warning('killing iio-capture process [%d]...', + self.process.pid) + self.process.kill() + def reset(self, sites=None, kinds=None, channels=None): super(AcmeCapeInstrument, self).reset(sites, kinds, channels) self.raw_data_file = tempfile.mkstemp('.csv')[1] @@ -98,6 +104,7 @@ class AcmeCapeInstrument(Instrument): .format(self.process.returncode, output)) if not os.path.isfile(self.raw_data_file): raise HostError('Output CSV not generated.') + self.process = None def get_data(self, outfile): if os.stat(self.raw_data_file).st_size == 0: