Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence warning that may happen during teardown of simulated instruments. #5737

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/qcodes/instrument/visa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pyvisa
import pyvisa.constants as vi_const
import pyvisa.resources
from pyvisa.errors import InvalidSession

import qcodes.validators as vals
from qcodes.logger import get_instrument_logger
Expand Down Expand Up @@ -264,7 +265,15 @@ def close(self) -> None:
# The pyvisa-sim visalib has a session attribute but the resource manager is not generic in the
# visalib type so we cannot get it in a type safe way
known_sessions = getattr(self.resource_manager.visalib, "sessions", ())
session_found = self.resource_manager.session in known_sessions

try:
this_session = self.resource_manager.session
except InvalidSession:
# this may be triggered when the resource has already been closed
# in that case there is nothing that we can do.
this_session = None

session_found = this_session is not None and this_session in known_sessions

n_sessions = len(known_sessions)
# if this instrument is the last one or there are no connected instruments its safe to reset the device
Expand Down
Loading