Skip to content
Snippets Groups Projects
Commit 11fd756c authored by Arne Babenhauserheide's avatar Arne Babenhauserheide
Browse files

Works without X11 by detecting missing X11 safely and switching to a non-X11...

Works without X11 by detecting missing X11 safely and switching to a non-X11 dependent backend if needed.

2b5d5c96d69a: without X use Agg backend for matplotlib.
0f9bc0082666: FIX: carbontracker did not accept Agg backend. Set backend before doing any other initialization.
a39f395df80b: Finally catch X11 errors the hard way: spawning a new process which tries to use X11. If that fails, use Agg as backend.
parent b4df39c6
No related branches found
No related tags found
No related merge requests found
......@@ -96,8 +96,3 @@ if __name__ == "__main__":
show()
......@@ -120,6 +120,7 @@ def ToDectime(dd):
""" convert a datetime object to a decimal date """
import datetime
import calendar
from matplotlib.pylab import date2num
Days0=date2num(datetime.datetime(dd.year,1,1))
......
......@@ -4,6 +4,19 @@
# First order of business is always to make all other python modules accessible through the path
#################################################################################################
__realimport__ = __import__
def _printimport(*args, **kwds):
"""print each import."""
print "importing:", args[:1]
if args[0] == "matplotlib":
print args, kwds
raise Exception("Imported matplotlib here!")
return __realimport__(*args, **kwds)
# debugging info to get the actual import order.
#import __builtin__
#__builtin__.__import__ = _printimport
import sys
import os
import logging
......@@ -13,6 +26,14 @@ dummy = sys.path.append(os.getcwd())
# Next, import the tools needed to initialize a data assimilation cycle
#################################################################################################
# without X11 use Agg as matplotlib backend.
from subprocess import call
def hasWorkingX11():
return not call(["python", "-c", "import pylab as pl; pl.ion(); pl.plot((0,0))"])
if not "DISPLAY" in os.environ or not hasWorkingX11():
import matplotlib
matplotlib.use("Agg")
from da.tools.initexit import StartLogger
from da.tools.initexit import ValidateOptsArgs
from da.tools.initexit import ParseOptions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment