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

do not load notebook elements when no notebook is running #278

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions qcodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +31,9 @@
'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':
from qcodes.widgets.widgets import show_subprocess_widget

from qcodes.station import Station
from qcodes.loops import get_bg, halt_bg, Loop
Expand Down
8 changes: 6 additions & 2 deletions qcodes/plots/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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)

Expand Down
1 change: 0 additions & 1 deletion qcodes/plots/qcmatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions qcodes/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import math
import sys
import os
import io
import numpy as np
import json
Expand Down Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy Issue found: Trailing whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy Issue found: Trailing whitespace

"""
return os.environ.get('QCODESFRONTEND', 'notebook')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really use environment variables for this?
I'd prefer config files so much more, @giulioungaretti @alexcjohnson


def in_notebook():
"""
Expand Down