Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7455c47

Browse files
committed
Don't crash the plot_directive if the plot itself fails.
svn path=/trunk/matplotlib/; revision=7806
1 parent 10fa94d commit 7455c47

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def run_code(plot_path, function_name, plot_code):
170170
stdout = sys.stdout
171171
sys.stdout = cStringIO.StringIO()
172172
os.chdir(path)
173+
fd = None
173174
try:
174175
fd = open(fname)
175176
module = imp.load_module(
@@ -178,7 +179,8 @@ def run_code(plot_path, function_name, plot_code):
178179
del sys.path[0]
179180
os.chdir(pwd)
180181
sys.stdout = stdout
181-
fd.close()
182+
if fd is not None:
183+
fd.close()
182184

183185
if function_name is not None:
184186
getattr(module, function_name)()

0 commit comments

Comments
 (0)