Observed issue
==============
An exception is thrown when deleting a _TraceTestApplication object that
has thrown an exception during it's `__init__` method. Eg.
```
Exception ignored in: <function _TraceTestApplication.__del__ at 0x7fcbc9a21620>
Traceback (most recent call last):
File "/home/kstewart/src/efficios/lttng/master/src/lttng-tools/tests/utils/lttngtest/environment.py", line 348, in __del__
self._process.kill()
^^^^^^^^^^^^^
AttributeError: '_TraceTestApplication' object has no attribute '_process'
```
Similarly, this can happen to _WaitTraceTestApplication objects.
Cause
=====
The object's `_process` attribute is set during `__init__`; however,
if an exception is thrown during `subprocess.Popen` a value is never
assigned to the attribute.
Solution
========
A default value for the `_process` attribute is set and checked as
part of the condition when executing the `__del__` method.
Known drawbacks
===============
None.
Change-Id: I2220ae764be49fafb3b977a5e723931421485d63
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
wait_before_exit=False, # type: bool
wait_before_exit_file_path=None, # type: Optional[pathlib.Path]
):
wait_before_exit=False, # type: bool
wait_before_exit_file_path=None, # type: Optional[pathlib.Path]
):
self._environment = environment # type: Environment
self._iteration_count = event_count
# File that the application will wait to see before tracing its events.
self._environment = environment # type: Environment
self._iteration_count = event_count
# File that the application will wait to see before tracing its events.
return str(path)
def __del__(self):
return str(path)
def __del__(self):
- if not self._has_returned:
+ if self._process is not None and not self._has_returned:
# This is potentially racy if the pid has been recycled. However,
# we can't use pidfd_open since it is only available in python >= 3.9.
self._process.kill()
# This is potentially racy if the pid has been recycled. However,
# we can't use pidfd_open since it is only available in python >= 3.9.
self._process.kill()
def __init__(self, binary_path, environment):
# type: (pathlib.Path, Environment)
def __init__(self, binary_path, environment):
# type: (pathlib.Path, Environment)
self._environment = environment # type: Environment
self._has_returned = False
self._environment = environment # type: Environment
self._has_returned = False
self._has_returned = True
def __del__(self):
self._has_returned = True
def __del__(self):
- if not self._has_returned:
+ if self._process is not None and not self._has_returned:
# This is potentially racy if the pid has been recycled. However,
# we can't use pidfd_open since it is only available in python >= 3.9.
self._process.kill()
# This is potentially racy if the pid has been recycled. However,
# we can't use pidfd_open since it is only available in python >= 3.9.
self._process.kill()