Skip to content

Commit

Permalink
don't unregister interrupted post-exec functions
Browse files Browse the repository at this point in the history
only unregister on real Exceptions.

also put close/cleanup for the inline backend calls inside `finally` block,
to ensure that the state is clean on the next round, even if show/flush is interrupted

closes gh-992
  • Loading branch information
minrk authored and fperez committed Nov 20, 2011
1 parent 293d3ee commit f3fe1c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
5 changes: 4 additions & 1 deletion IPython/core/interactiveshell.py
Expand Up @@ -2426,7 +2426,10 @@ def run_cell(self, raw_cell, store_history=False):
continue
try:
func()
except:
except KeyboardInterrupt:
print >> io.stderr, "\nKeyboardInterrupt"
except Exception:
print >> io.stderr, "Disabling failed post-execution function: %s" % func
self.showtraceback()
# Deactivate failing function
self._post_execute[func] = False
Expand Down
28 changes: 16 additions & 12 deletions IPython/zmq/pylab/backend_inline.py
Expand Up @@ -97,11 +97,13 @@ def show(close=None):
"""
if close is None:
close = InlineBackend.instance().close_figures
for figure_manager in Gcf.get_all_fig_managers():
send_figure(figure_manager.canvas.figure)
if close:
matplotlib.pyplot.close('all')
show._to_draw = []
try:
for figure_manager in Gcf.get_all_fig_managers():
send_figure(figure_manager.canvas.figure)
finally:
show._to_draw = []
if close:
matplotlib.pyplot.close('all')



Expand Down Expand Up @@ -146,13 +148,15 @@ def flush_figures():
# ignore the tracking, just draw and close all figures
return show(True)

# exclude any figures that were closed:
active = set([fm.canvas.figure for fm in Gcf.get_all_fig_managers()])
for fig in [ fig for fig in show._to_draw if fig in active ]:
send_figure(fig)
# clear flags for next round
show._to_draw = []
show._draw_called = False
try:
# exclude any figures that were closed:
active = set([fm.canvas.figure for fm in Gcf.get_all_fig_managers()])
for fig in [ fig for fig in show._to_draw if fig in active ]:
send_figure(fig)
finally:
# clear flags for next round
show._to_draw = []
show._draw_called = False


def send_figure(fig):
Expand Down

0 comments on commit f3fe1c1

Please sign in to comment.