When it can't initialize the backend, the matplotlib crashes with a
runtime error. For example, I've used `~/.matplotlib/matplotlibrc` to
select the GTKAgg backend as my default. When I log in without X,
running the previous version of slow_bend.py would produce:
$ slow_bend.py --help
/usr/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
warnings.warn(str(e), _gtk.Warning)
/usr/lib/python2.7/site-packages/matplotlib/backends/backend_gtk.py:48: GtkWarning: IA__gdk_cursor_new_for_display: assertion `GDK_IS_DISPLAY (display)' failed
cursors.MOVE : gdk.Cursor(gdk.FLEUR),
Traceback (most recent call last):
File "/home/wking/bin/slow_bend.py", line 39, in <module>
from matplotlib import pyplot as _pyplot
...
RuntimeError: could not create GdkCursor object
try:
import numpy as _numpy
from matplotlib import pyplot as _pyplot
-except ImportError, _matplotlib_import_error:
+except (ImportError, RuntimeError), _matplotlib_import_error:
_pyplot = None
import pycomedi.device as _pycomedi_device