You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wx crashes on exit if figure not shown and not explicitly closed #3316
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)'
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
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
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: .
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])
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).
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...
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
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()?
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).
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.
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:
importwximportpylabapp=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.
Activity
[-]Crashes on windows[/-][+]Crashes on windows if figure not explicitly closed[/+]mdboom commentedon Jul 27, 2014
Can you provide the full output from the crash?
WeatherGod commentedon Jul 27, 2014
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:
ibell commentedon Jul 27, 2014
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:
tacaswell commentedon Aug 17, 2014
@Tillsten can you reproduce this?
tacaswell commentedon Aug 17, 2014
@ibell Could you re-try this with one of the RCs for 1.4.0?
ericdill commentedon Aug 17, 2014
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: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)Hope this helps, mpl devs!
ibell commentedon Aug 17, 2014
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
tacaswell commentedon Aug 17, 2014
@ibell https://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.4.0rc2/
tacaswell commentedon Aug 17, 2014
And the code runs fine on linux.
22 remaining items
tacaswell commentedon Jul 1, 2015
Interestingly this lead me to find: #4572
For reference (even if it looks a bit useless to me):
If you try to call
destroyon 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.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).
OceanWolf commentedon Jul 4, 2015
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...
[-]Crashes on windows if figure not explicitly closed[/-][+]wx crashes on exit if figure not shown and not explicitly closed [/+]heroxbd commentedon Jul 9, 2015
@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
WeatherGod commentedon Jul 9, 2015
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 commentedon Jul 13, 2015
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-wxonly 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).
heroxbd commentedon Jul 14, 2015
Benjamin Root notifications@github.com writes:
Yes, it segfaults no matter if you called savefig() or not.
Test if a frame is not already being deleted before trying to Destroy.
RobinD42 commentedon Dec 8, 2015
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
atexitprocessing. Specifically the frame was already in the process of being deleted when theDestroymethod was being calling again, and so it tried using a now-bad pointer to call the C++Destroymethod. The reason it didn't happen when with window was shown is because the frame would delete itself when it was closed, before theatexitcode started.PR #5639 will fix this and should be safe for all versions of wx.
bikramditya commentedon Dec 30, 2015
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
zong commentedon Apr 10, 2016
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:
Does not occur if wx alone is imported. Does not occur with either matplotlib 1.4.3 or wxPython 2.8.12.1.
efiring commentedon Apr 10, 2016
@ZonG0 I think you are seeing a different problem. If you are creating your own
wx.Appyou should not be usingpylabat all. See the embedding examples in http://matplotlib.org/examples/user_interfaces/index.html.zong commentedon Apr 10, 2016
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