From 9ccc96a55e66c00e73067a10a9f20d5d584ea9a0 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Mon, 25 Sep 2023 12:50:55 +0200 Subject: [PATCH] handle that _init could be missing --- qcodes/instrument/visa.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index 009c639b09e..bea9f58f485 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +import warnings from collections.abc import Sequence from importlib.resources import as_file, files from typing import Any @@ -272,7 +273,15 @@ def close(self) -> None: # see other issues for more context # https://github.com/QCoDeS/Qcodes/issues/5356 and # https://github.com/pyvisa/pyvisa-sim/issues/82 - self.resource_manager.visalib._init() + try: + self.resource_manager.visalib._init() + except AttributeError: + warnings.warn( + "The installed version of pyvisa-sim does not have an `_init` method " + "in its visa library implementation. Cannot reset simulated instrument state. " + "On reconnect the instrument may retain settings set in this session." + ) + super().close() def write_raw(self, cmd: str) -> None: