matplotlib - Unable to catch RuntimeError in python -
i writing python 2.7 plotting script using matplotlib , want display plotted, unless run non-x session on institute server batch-plotting. such cases tell not display anything.
however don't want stop if forget doing that, why i'm trying catch runtimeerror exception so:
try: pyplot.show() except runtimeerror: print 'could not display figure. no x-session?' except: print 'unexpected error:' raise
doing this, however, still i'd without trying catch anything, namely traceback and:
runtimeerror: invalid display variable
it doesn't print 'unexpected error', doesn't run second except.
what missing? might simple because i'm rather new this.
edit:
the exception seems thrown before try display plot, maybe different problem altogether.
the problem somewhere else altogether. hava use different backend matplotlib if i'm running non-x session. checking display-variable cel suggested , calling
matplotlib.use('agg')
on non-x sessions before importing pyplot solves problem.
Comments
Post a Comment