Skip to content
Open
Changes from all commits
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
19 changes: 19 additions & 0 deletions qcodes/instrument/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,25 @@ def __call__(cls, *args: Any, **kwargs: Any) -> Any:
Overloads `type.__call__` to add code that runs only if __init__ completes
successfully.
"""
if len(args) >= 1:
name = args[0]
else:
name = kwargs.get("name", None)
existing_instr = None
if name is not None:

try:
existing_instr = cls.find_instrument(name, cls) # type: ignore[attr-defined]
except (KeyError, TypeError):
pass

if existing_instr is not None:
log.info(f"Reusing existing instrument {name}")
# todo this is only really safe if this is the same instrument
# e.g. address should be the same but that is a trait only implemented
# in subclasses
return existing_instr

new_inst = super().__call__(*args, **kwargs)
is_abstract = new_inst._is_abstract()
if is_abstract:
Expand Down