Skip to content

Commit 49d7082

Browse files
maximilianlucjenshnielsen
authored andcommitted
feature: replace __del__ with weakref.finalize()
1 parent a450af6 commit 49d7082

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

qcodes/instrument/instrument.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(
6969
super().__init__(name=name, metadata=metadata, label=label)
7070

7171
self.add_parameter("IDN", get_cmd=self.get_idn, vals=Anything())
72+
weakref.finalize(self, self.__finalize)
7273

7374
def get_idn(self) -> dict[str, str | None]:
7475
"""
@@ -143,7 +144,7 @@ def __repr__(self) -> str:
143144
"""Simplified repr giving just the class and name."""
144145
return f"<{type(self).__name__}: {self.name}>"
145146

146-
def __del__(self) -> None:
147+
def __finalize(self) -> None:
147148
"""Close the instrument and remove its instance record."""
148149
try:
149150
self.close()

0 commit comments

Comments
 (0)