Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylab figure becomes unresponsive after an error #2583

Closed
olcc opened this issue Nov 7, 2013 · 7 comments
Closed

Pylab figure becomes unresponsive after an error #2583

olcc opened this issue Nov 7, 2013 · 7 comments

Comments

@olcc
Copy link

olcc commented Nov 7, 2013

Hello,

I use ipython --pylab for plotting a graph (like plot(rand(5))) and I add a label: xlabel(r"$\heta$")
But, oh, I made a mistake! I forget the t in the word \theta!
Bad luck, the pylab window is now unresponsive...

The problem is not the error, but the fact that the figure is now unresponsive and needs to be made entirely again. Expected behavior: interactive IPython/pylab should still be responsive after this error. The error is the following.

In [8]: Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1473, in __call__
    return self.func(*args)
(...)
  File "/usr/lib/pymodules/python2.7/matplotlib/mathtext.py", line 2345, in parse   
    str(err)]))
ValueError:
\heta
^
Unknown symbol: \heta (at char 0), (line:1, col:1)
  • Debian distribution, with the following details:
    {'commit_hash': '',
    'commit_source': '(none found)',
    'default_encoding': 'UTF-8',
    'ipython_path': '/usr/lib/python2.7/dist-packages/IPython',
    'ipython_version': '0.13.2',
    'os_name': 'posix',
    'platform': 'Linux-3.2.0-2-amd64-x86_64-with-debian-wheezy-sid',
    'sys_executable': '/usr/bin/python',
    'sys_platform': 'linux2',
    'sys_version': '2.7.5+ (default, Jun 2 2013, 13:26:34) \n[GCC 4.7.3]'}

Best regards,
Olivier

@mdboom
Copy link
Member

mdboom commented Nov 11, 2013

I can't reproduce this. What version of matplotlib is this?

@olcc
Copy link
Author

olcc commented Nov 11, 2013

matplotlib.__version__ = '1.3.1'

@pelson
Copy link
Member

pelson commented Dec 12, 2013

@olcc - can you provide a SSCCE (short, self contained, correct, example)?

@olcc
Copy link
Author

olcc commented Dec 12, 2013

It is all written above...
$ ipython --pylab

plot(rand(5)) # produces a graph
xlabel(r"$\heta$") # many errors are written on the screen... but it's just normal
# but now the figure is unresponsive
xlabel(r"$\theta$") # ...doesn't work

@tacaswell
Copy link
Member

If you throw a plt.draw() in it will draw correctly, but draw_if_interactive() seems to no longer work. By 'non-responsive' the OP means pyplot does not auto-magically update, not that the gui is acctually non-responsive.

The reason is that the way draw_idle works (atleast for qt4, I assume it is similar for others)

    def draw_idle(self):
        'update drawing area only if idle'
        d = self._idle
        self._idle = False

        def idle_draw(*args):
            self.draw()
            self._idle = True
        if d:
            QtCore.QTimer.singleShot(0, idle_draw)

idle_draw fails to finish (because draw blows up) so self._idle is never set to True again, so draw_idle always falls through with a no-op after the exception.

I think the solution is to replace idle_draw with

def idle_draw():
    try:
        self.draw()
    finally:
        self._idle = True

This works for QT4, I would like some feed back that this is the right way to do this before I do all of the backends.

@WeatherGod
Copy link
Member

This makes a lot of sense to me. It keeps with the principle of keeping
your objects in as valid of a state as possible.

My only concern is if this would lead to odd infinite loop situations in
non-interactive backends where it keeps on trying to execute draw() when
will just keep throwing an exception, but I can't really imagine how that
might happen.

On Thu, Dec 12, 2013 at 4:20 PM, Thomas A Caswell
notifications@github.comwrote:

If you throw a plt.draw() in it will draw correctly, but
draw_if_interactive() seems to no longer work. By 'non-responsive' the OP
means pyplot does not auto-magically update, not that the gui is
acctually non-responsive.

The reason is that the way draw_idle works (atleast for qt4, I assume it
is similar for others)

def draw_idle(self):
    'update drawing area only if idle'
    d = self._idle
    self._idle = False

    def idle_draw(*args):
        self.draw()
        self._idle = True
    if d:
        QtCore.QTimer.singleShot(0, idle_draw)

idle_draw fails to finish (because draw blows up) so self._idle is never
set to True again, so draw_idle always falls through with a no-op after
the exception.

I think the solution is to replace idle_draw with

def idle_draw():
try:
self.draw()
finally:
self._idle = True

This works for QT4, I would like some feed back that this is the right way
to do this before I do all of the backends.


Reply to this email directly or view it on GitHubhttps://github.com//issues/2583#issuecomment-30462870
.

@tacaswell
Copy link
Member

@olcc I am closing this as it should have bee fixed in #2677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants