From 70da7acb6dd9e02521da20b5711f1c5967855146 Mon Sep 17 00:00:00 2001 From: Pieter Date: Fri, 22 Jul 2016 12:51:20 +0200 Subject: [PATCH 1/2] do not load notebook elements when no notebook is running --- qcodes/__init__.py | 10 ++++++++-- qcodes/plots/base.py | 8 ++++++-- qcodes/plots/qcmatplotlib.py | 1 - qcodes/utils/helpers.py | 8 ++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/qcodes/__init__.py b/qcodes/__init__.py index f7a65d3adea..2b8932eaca6 100644 --- a/qcodes/__init__.py +++ b/qcodes/__init__.py @@ -2,13 +2,16 @@ # flake8: noqa (we don't need the "<...> imported but unused" error) +import os # just for convenience in debugging, so we don't have to # separately import multiprocessing from multiprocessing import active_children from qcodes.version import __version__ from qcodes.process.helpers import set_mp_method -from qcodes.utils.helpers import in_notebook +from qcodes.utils.helpers import in_notebook, frontend + + # code that should only be imported into the main (notebook) thread # in particular, importing matplotlib in the side processes takes a long @@ -28,7 +31,10 @@ 'try "from qcodes.plots.pyqtgraph import QtPlot" ' 'to see the full error') - from qcodes.widgets.widgets import show_subprocess_widget + # only load the show_subprocess_widget when running jupyter notebook + if frontend()=='notebook': + print('load show_subprocess_widget') + from qcodes.widgets.widgets import show_subprocess_widget from qcodes.station import Station from qcodes.loops import get_bg, halt_bg, Loop diff --git a/qcodes/plots/base.py b/qcodes/plots/base.py index 2c7dcc824dc..ddda7857335 100644 --- a/qcodes/plots/base.py +++ b/qcodes/plots/base.py @@ -3,8 +3,12 @@ ''' from IPython.display import display -from qcodes.widgets.widgets import HiddenUpdateWidget +from qcodes.utils.helpers import frontend +if frontend()=='notebook': + from qcodes.widgets.widgets import HiddenUpdateWidget +else: + HiddenUpdateWidget=None class BasePlot: @@ -26,7 +30,7 @@ def __init__(self, interval=1, data_keys='xyz'): self.data_updaters = set() self.interval = interval - if interval: + if interval and HiddenUpdateWidget: self.update_widget = HiddenUpdateWidget(self.update, interval) display(self.update_widget) diff --git a/qcodes/plots/qcmatplotlib.py b/qcodes/plots/qcmatplotlib.py index be55d65b7e5..2824df0f31d 100644 --- a/qcodes/plots/qcmatplotlib.py +++ b/qcodes/plots/qcmatplotlib.py @@ -10,7 +10,6 @@ from .base import BasePlot - class MatPlot(BasePlot): ''' Plot x/y lines or x/y/z heatmap data. The first trace may be included diff --git a/qcodes/utils/helpers.py b/qcodes/utils/helpers.py index ba269dd7599..4d0e33488fb 100644 --- a/qcodes/utils/helpers.py +++ b/qcodes/utils/helpers.py @@ -4,6 +4,7 @@ import logging import math import sys +import os import io import numpy as np import json @@ -35,6 +36,13 @@ def tprint(string, dt=1, tag='default'): print(string) _tprint_times[tag] = time.time() +def frontend(): + """ Return frontend used + + Returns + frontend (string): frontend used. Default is notebook + """ + return os.environ.get('QCODESFRONTEND', 'notebook') def in_notebook(): """ From c293fb9a865179ab1c67fb6979913f65e35fe423 Mon Sep 17 00:00:00 2001 From: Pieter Date: Fri, 22 Jul 2016 12:55:02 +0200 Subject: [PATCH 2/2] remove print statement --- qcodes/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qcodes/__init__.py b/qcodes/__init__.py index 2b8932eaca6..070db3c3b88 100644 --- a/qcodes/__init__.py +++ b/qcodes/__init__.py @@ -33,7 +33,6 @@ # only load the show_subprocess_widget when running jupyter notebook if frontend()=='notebook': - print('load show_subprocess_widget') from qcodes.widgets.widgets import show_subprocess_widget from qcodes.station import Station