Skip to content

wx crashes on exit if figure not shown and not explicitly closed  #3316

Closed

Description

@ibell

On windows, with the wxagg backend, if the figure is not explicitly closed, python crashes. This crashes:

python -c "import matplotlib.pyplot as plt; plt.plot([0,1],[1,4])"

versions:

C:\Users\Belli>python
Python 2.7.6 |Continuum Analytics, Inc.| (default, May 27 2014, 15:00:33) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io and https://binstar.org
>>> import matplotlib
>>> matplotlib.__version__
'1.3.1'
>>> import wx
>>> wx.version()
'3.0.0.0 msw (classic)'

Activity

  1. changed the title [-]Crashes on windows[/-] [+]Crashes on windows if figure not explicitly closed[/+] on Jul 27, 2014
  2. mdboom commented on Jul 27, 2014

    @mdboom
    Member

    Can you provide the full output from the crash?

  3. WeatherGod commented on Jul 27, 2014

    @WeatherGod
    Member

    Does anybody remember if 1.3.1 has the updated wx Backend or not?
    On Jul 27, 2014 9:33 AM, "Ian Bell" notifications@github.com wrote:

    On windows, with the wxagg backend, if the figure is not explicitly
    closed, python crashes. This crashes:

    python -c "import matplotlib.pyplot as plt; plt.plot([0,1],[1,4])"

    versions:

    C:\Users\Belli>python
    Python 2.7.6 |Continuum Analytics, Inc.| (default, May 27 2014, 15:00:33) [MSC v.1500 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io and https://binstar.org

    import matplotlib
    matplotlib.version
    '1.3.1'
    import wx
    wx.version()
    '3.0.0.0 msw (classic)'

    —
    Reply to this email directly or view it on GitHub
    #3316.

  4. ibell commented on Jul 27, 2014

    @ibell
    Author

    All I get is a "python has stopped working" popup, no other output.

    On Sun, Jul 27, 2014 at 7:31 PM, Benjamin Root notifications@github.com
    wrote:

    Does anybody remember if 1.3.1 has the updated wx Backend or not?
    On Jul 27, 2014 9:33 AM, "Ian Bell" notifications@github.com wrote:

    On windows, with the wxagg backend, if the figure is not explicitly
    closed, python crashes. This crashes:

    python -c "import matplotlib.pyplot as plt; plt.plot([0,1],[1,4])"

    versions:

    C:\Users\Belli>python
    Python 2.7.6 |Continuum Analytics, Inc.| (default, May 27 2014,
    15:00:33) [MSC v.1500 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io and https://binstar.org

    import matplotlib
    matplotlib.version
    '1.3.1'
    import wx
    wx.version()
    '3.0.0.0 msw (classic)'

    —
    Reply to this email directly or view it on GitHub
    #3316.

    —
    Reply to this email directly or view it on GitHub
    #3316 (comment)
    .

  5. tacaswell commented on Aug 17, 2014

    @tacaswell
    Member

    @Tillsten can you reproduce this?

  6. added this to the v1.4.x milestone on Aug 17, 2014
  7. tacaswell commented on Aug 17, 2014

    @tacaswell
    Member

    @ibell Could you re-try this with one of the RCs for 1.4.0?

  8. ericdill commented on Aug 17, 2014

    @ericdill
    Contributor

    Running the OP's command does not produce an error on my machine (win 7 x64).

    However, at the advice of @tacaswell , running python -c "import matplotlib; matplotlib.use('wxagg'); import matplotlib.pyplot as plt; plt.plot([0,1],[1,4])" gives the python.exe has stopped working window:
    image.

    If I click Debug the program, VS2008 pops up and shows that python terminated due to an Unhandled exception at 0x08b1fb72 in python.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.

    Digging a little deeper results in a list of disassembly code with an arrow pointing to this line: 0000000008B1FB72 call qword ptr [rdx+0A0h]

    As this was not terribly helpful (at least for me), running the same code in debug mode of PyCharm Community results in this error: Exception TypeError: "'NoneType' object is not callable" in <bound method Pen.<lambda> of <wx._gdi.Pen; proxy of <Swig Object of type 'wxPen *' at 0x77963a0> >> ignored (The code that produces this is below)

    import matplotlib
    matplotlib.use('wxagg')
    import matplotlib.pyplot as plt
    plt.plot([0,1],[1,4])
    

    Hope this helps, mpl devs!

  9. ibell commented on Aug 17, 2014

    @ibell
    Author

    binaries? Building on windows isn't exactly a lot of fun...

    On Sun, Aug 17, 2014 at 11:48 PM, Thomas A Caswell <notifications@github.com

    wrote:

    @ibell https://github.com/ibell Could you re-try this with one of the
    RCs for 1.4.0?

    —
    Reply to this email directly or view it on GitHub
    #3316 (comment)
    .

  10. tacaswell commented on Aug 17, 2014

    @tacaswell
    Member

    And the code runs fine on linux.

  11. 22 remaining items

  12. removed this from the milestone on Jul 1, 2015
  13. tacaswell commented on Jul 1, 2015

    @tacaswell
    Member

    Interestingly this lead me to find: #4572

    For reference (even if it looks a bit useless to me):

    22:15 $ gdb -return-child-result -batch -ex r -ex bt --args python2  -c "import matplotlib; matplotlib.use('wxagg'); import matplotlib.pyplot as plt; plt.plot([0,1],[1,4]);"  
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/usr/lib/libthread_db.so.1".
    22:15:35: Warning: Mismatch between the program and library build versions detected.
    The library used 3.0 (wchar_t,compiler with C++ ABI 1008,wx containers,compatible with 2.8),
    and wxPython used 3.0 (wchar_t,compiler with C++ ABI 1002,wx containers,compatible with 2.8).
    
    Program received signal SIGSEGV, Segmentation fault.
    0x0000555556b9eb80 in ?? ()
    #0  0x0000555556b9eb80 in ?? ()
    #1  0x00007fffeb9c6075 in ?? () from /usr/lib/python2.7/site-packages/wx-3.0-gtk2/wx/_core_.so
    #2  0x00007ffff7af4d6d in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
    #3  0x00007ffff7af5abc in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
    #4  0x00007ffff7a824ad in function_call () from /usr/lib/libpython2.7.so.1.0
    #5  0x00007ffff7a5d9e3 in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
    #6  0x00007ffff7a6c7c7 in instancemethod_call () from /usr/lib/libpython2.7.so.1.0
    #7  0x00007ffff7a5d9e3 in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
    #8  0x00007ffff7af2671 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
    #9  0x00007ffff7af5abc in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
    #10 0x00007ffff7af4786 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
    #11 0x00007ffff7af5abc in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
    #12 0x00007ffff7af4786 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
    #13 0x00007ffff7af5abc in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
    #14 0x00007ffff7a824ad in function_call () from /usr/lib/libpython2.7.so.1.0
    #15 0x00007ffff7a5d9e3 in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
    #16 0x00007ffff7af2671 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
    #17 0x00007ffff7af5abc in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
    #18 0x00007ffff7a823cc in function_call () from /usr/lib/libpython2.7.so.1.0
    #19 0x00007ffff7a5d9e3 in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
    #20 0x00007ffff7aeeed7 in PyEval_CallObjectWithKeywords () from /usr/lib/libpython2.7.so.1.0
    #21 0x00007ffff7b10bf7 in Py_Finalize () from /usr/lib/libpython2.7.so.1.0
    #22 0x00007ffff7b22dd4 in Py_Main () from /usr/lib/libpython2.7.so.1.0
    #23 0x00007ffff7474790 in __libc_start_main () from /usr/lib/libc.so.6
    #24 0x0000555555554859 in _start ()
    

    If you try to call destroy on an un-shown figure manager you don't get a seg-fault. This looks like a race-condition between the atexit function between wx and matplotlib.

    22:21 $ git diff
    diff --git a/lib/matplotlib/_pylab_helpers.py b/lib/matplotlib/_pylab_helpers.py
    index c5ea8cc..cf6011c 100644
    --- a/lib/matplotlib/_pylab_helpers.py
    +++ b/lib/matplotlib/_pylab_helpers.py
    @@ -149,4 +149,4 @@ class Gcf(object):
                 if force or f_mgr.canvas.figure.stale:
                     f_mgr.canvas.draw_idle()
    
    -atexit.register(Gcf.destroy_all)
    +# atexit.register(Gcf.destroy_all)

    prevents the segfault.

    I would be interested if this could be reproduced using only WX classes.

    I have re-milestoned this as 'proposed next point release' as I do not think that this should be a blocker for the next release (but am open to arguments otherwise).

  14. OceanWolf commented on Jul 4, 2015

    @OceanWolf
    Member

    From reading the above it looks like this bug affects more than Windows, I couldn't tell if it affects Linux though, anyway, we should change the title of this bug.

    Basically if I know what to test, I can see if MEP27 fixes it as a lot of code involved in window generation/destruction has been refactored, if this happened due to a race condition (or even another problem), then it stands a good chance that I have already fixed it...

  15. changed the title [-]Crashes on windows if figure not explicitly closed[/-] [+]wx crashes on exit if figure not shown and not explicitly closed [/+] on Jul 4, 2015
  16. heroxbd commented on Jul 9, 2015

    @heroxbd

    @OceanWolf, thanks for your input. Unfortunately backend-refactor-wx at https://github.com/OceanWolf/matplotlib.git does not fix the bug.

    $ python -c "import matplotlib; matplotlib.use('wxagg'); import matplotlib.pyplot as plt; plt.plot([0,1],[1,4]);"
    Segmentation fault

  17. WeatherGod commented on Jul 9, 2015

    @WeatherGod
    Member

    I am thinking that a quick-n-dirty solution to this problem would be for us
    to register a wrapped function for atexit() that would detect if
    destruction has already happened. The other way to approach this is to
    figure out what is it that plt.show() does in Wx that prevents this from
    happening.

    Just curious, does the segfault happen if you do a fig.savefig()?

    On Thu, Jul 9, 2015 at 5:55 AM, heroxbd notifications@github.com wrote:

    @OceanWolf https://github.com/OceanWolf, thanks for your input.
    Unfortunately backend-refactor-wx at
    https://github.com/OceanWolf/matplotlib.git does not fix the bug.

    $ python -c "import matplotlib; matplotlib.use('wxagg'); import
    matplotlib.pyplot as plt; plt.plot([0,1],[1,4]);"
    Segmentation fault

    —
    Reply to this email directly or view it on GitHub
    #3316 (comment)
    .

  18. OceanWolf commented on Jul 13, 2015

    @OceanWolf
    Member

    I think I see the problem, we create a window, but never actually show it, so we never have anything GUI to close.

    @heroxbd Thanks for the code. I can see why MEP27 doesn't fix it, though I think it will make it easier to fix (note also that backend-refactor-wx only has a rough implementation of MEP27 needing a rebase from the main MEP27 branch which will happen as soon as I get the all clear to carry on, i.e. once @tacaswell has the time to do a full read through).

    When I resume the MEP27 work on the other backends I will take a look at fixing this (though I might need a reminder).

  19. heroxbd commented on Jul 14, 2015

    @heroxbd

    Benjamin Root notifications@github.com writes:

    Just curious, does the segfault happen if you do a fig.savefig()?

    Yes, it segfaults no matter if you called savefig() or not.

  20. added a commit that references this issue on Dec 8, 2015
    187c5bc
  21. RobinD42 commented on Dec 8, 2015

    @RobinD42
    Contributor

    Hi all,

    I finally got a chance to dig into this issue with the debugger. The guesses so far have been on the right track about a conflict with wx's cleanup and atexit processing. Specifically the frame was already in the process of being deleted when the Destroy method was being calling again, and so it tried using a now-bad pointer to call the C++ Destroy method. The reason it didn't happen when with window was shown is because the frame would delete itself when it was closed, before the atexit code started.

    PR #5639 will fix this and should be safe for all versions of wx.

  22. bikramditya commented on Dec 30, 2015

    @bikramditya

    Hi All,
    I am using WXpython to build GUI. I observed the same issue when closing the second frame.
    Where should i add the fix suggested by RobinD42

  23. zong commented on Apr 10, 2016

    @zong

    Same as @bikramditya, can repro on OSX Yosemite with matplotlib 1.5.1 and wxPython 3.0.2.0 with the following three-line program, which hangs on the last line:

    import wx
    import pylab
    app = wx.App(False)

    Does not occur if wx alone is imported. Does not occur with either matplotlib 1.4.3 or wxPython 2.8.12.1.

  24. efiring commented on Apr 10, 2016

    @efiring
    Member

    @ZonG0 I think you are seeing a different problem. If you are creating your own wx.App you should not be using pylab at all. See the embedding examples in http://matplotlib.org/examples/user_interfaces/index.html.

  25. zong commented on Apr 10, 2016

    @zong

    I gave that only as a minimal example. There is something obviously wrong when two imports cannot coexist.

    Edit: Was able to get past the last line hanging by prepending

    import matplotlib
    matplotlib.use("wxAgg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions