Skip to content

Commit 2930378

Browse files
authored
Make sure ParameterFile __del__ works without exception. (#212)
The comment in the code has more information about why we are doing this. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 3cd7515 commit 2930378

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

launch_ros/launch_ros/parameter_descriptions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ def __init__(
179179
:param param_file: Path to a parameter file.
180180
:param allow_subst: Allow substitutions in the parameter file.
181181
"""
182+
# In Python, __del__ is called even if the constructor throws an
183+
# exception. It is possible for ensure_argument_type() below to
184+
# throw an exception and try to access these member variables
185+
# during cleanup, so make sure to initialize them here.
186+
self.__evaluated_param_file: Optional[Path] = None
187+
self.__created_tmp_file = False
188+
182189
ensure_argument_type(
183190
param_file,
184191
SomeSubstitutionsType_types_tuple + (os.PathLike, bytes),
@@ -196,8 +203,6 @@ def __init__(
196203
self.__param_file = normalize_to_list_of_substitutions(param_file)
197204
self.__allow_substs = normalize_typed_substitution(allow_substs, data_type=bool)
198205
self.__evaluated_allow_substs: Optional[bool] = None
199-
self.__evaluated_param_file: Optional[Path] = None
200-
self.__created_tmp_file = False
201206

202207
@property
203208
def param_file(self) -> Union[FilePath, List[Substitution]]:

0 commit comments

Comments
 (0)