Skip to content

Commit

Permalink
Avoid connecting to node when cache update set to false (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: Jinnapat Indrapiromkul <jinnapati@microsoft.com>
  • Loading branch information
einsmein and Jinnapat Indrapiromkul authored Oct 31, 2022
1 parent 2089055 commit 0846fda
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/zhinst/qcodes/qcodes_adaptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from datetime import datetime
import typing as t
from contextlib import contextmanager
from contextlib import contextmanager, nullcontext
from collections.abc import Mapping

import numpy as np
Expand Down Expand Up @@ -399,7 +399,7 @@ def snapshot(self, update: bool = True) -> dict:
Returns:
dict: Base snapshot.
"""
with self._snapshot_cache.snapshot(self._zi_node):
with self._snapshot_cache.snapshot(self._zi_node) if update else nullcontext():
return super().snapshot(update)

def print_readable_snapshot(self, update: bool = True, max_chars: int = 80) -> None:
Expand All @@ -418,7 +418,7 @@ def print_readable_snapshot(self, update: bool = True, max_chars: int = 80) -> N
readable snapshot will be cropped if this value is exceeded.
Defaults to 80 to be consistent with default terminal width.
"""
with self._snapshot_cache.snapshot(self._zi_node):
with self._snapshot_cache.snapshot(self._zi_node) if update else nullcontext():
return super().print_readable_snapshot(update, max_chars)


Expand Down Expand Up @@ -450,7 +450,7 @@ def snapshot(self, update: bool = True) -> dict:
Returns:
dict: Base snapshot.
"""
with self._snapshot_cache.snapshot(self._zi_node):
with self._snapshot_cache.snapshot(self._zi_node) if update else nullcontext():
return super().snapshot(update)

def print_readable_snapshot(self, update: bool = True, max_chars: int = 80) -> None:
Expand All @@ -469,7 +469,7 @@ def print_readable_snapshot(self, update: bool = True, max_chars: int = 80) -> N
readable snapshot will be cropped if this value is exceeded.
Defaults to 80 to be consistent with default terminal width.
"""
with self._snapshot_cache.snapshot(self._zi_node):
with self._snapshot_cache.snapshot(self._zi_node) if update else nullcontext():
return super().print_readable_snapshot(update, max_chars)


Expand Down Expand Up @@ -500,7 +500,7 @@ def snapshot(self, update: bool = True) -> dict:
Returns:
dict: Base snapshot.
"""
with self._snapshot_cache.snapshot():
with self._snapshot_cache.snapshot() if update else nullcontext():
return super().snapshot(update)

def print_readable_snapshot(self, update: bool = True, max_chars: int = 80) -> None:
Expand All @@ -519,7 +519,7 @@ def print_readable_snapshot(self, update: bool = True, max_chars: int = 80) -> N
readable snapshot will be cropped if this value is exceeded.
Defaults to 80 to be consistent with default terminal width.
"""
with self._snapshot_cache.snapshot():
with self._snapshot_cache.snapshot() if update else nullcontext():
return super().print_readable_snapshot(update, max_chars)


Expand Down

0 comments on commit 0846fda

Please sign in to comment.