NSLS-II / nslsii

NSLS-II related devices
BSD 3-Clause "New" or "Revised" License
11 stars 22 forks source link

qt_kicker doesn't work for all versions of notebooks #17

Closed jrmlhermitte closed 6 years ago

jrmlhermitte commented 6 years ago
from bluesky.utils import install_kicker
install_kicker()

NotImplementedErrorTraceback (most recent call last)
<ipython-input-30-1631198442ac> in <module>()
----> 1 install_kicker()

/opt/conda_envs/collection-2018-1.0/lib/python3.6/site-packages/bluesky/utils.py in install_kicker(loop, update_rate)
    719     else:
    720         raise NotImplementedError("The matplotlib backend {} is not yet "
--> 721                                   "supported.".format(backend))
    722 
    723 

NotImplementedError: The matplotlib backend module://ipykernel.pylab.backend_inline is not yet supported.

This is because install_kicker performs:

    import matplotlib
    backend = matplotlib.get_backend()
    if backend == 'nbAgg':
        install_nb_kicker(loop=loop, update_rate=update_rate)
    elif backend in ('Qt4Agg', 'Qt5Agg'):
        install_qt_kicker(loop=loop, update_rate=update_rate)
    else:
        raise NotImplementedError("The matplotlib backend {} is not yet "
                                  "supported.".format(backend))

and the output of the matplotlib backend is not one of the cases in the if statements:

import matplotlib
backend = matplotlib.get_backend()

backend
Out: 
'module://ipykernel.pylab.backend_inline'

Quick solution : Add 'module://ipykernel.pylab.backend_inline' to the possible cases in the if statements. But likely we should think more carefully on this.

jrmlhermitte commented 6 years ago

so at LIX, we modified the kicker line to this:

        # Make plots update live while scans run.
        if user_ns['get_ipython']().has_trait("kernel"):
            from bluesky.utils import install_nb_kicker
            install_nb_kicker()
        else:
            from bluesky.utils import install_qt_kicker
            install_qt_kicker()

this works. this should perhaps reside somewhere upstream (in bluesky install_nb_kicker?)

tacaswell commented 6 years ago

the inline backend is not interactive so it would not work.

at LIX, they should not be installing the kicker in an analysis notebook as you only need the kicker to get the RE to update figures while the asyncio event loop is running.

danielballan commented 6 years ago

I don't think has_kernel is the right approach: see this comment. If the backend is 'inline', then plots aren't interactive anywhere, so the correct behavior of install_kicker should be to do nothing, right?

jrmlhermitte commented 6 years ago

@tacaswell is right. We should not need RE in this instance. They don't run bluesky in notebooks. Given that discussion you refer @danielballan , it sounds safer to look for backend strings.

So I'll close this. :-)