wxPython因Segmentation故障而崩溃

时间:2013-08-30 16:18:03

标签: python linux wxpython segmentation-fault

我很困惑为什么我的应用程序崩溃了Segmentation fault。我有一个使用wxPython前端的python应用程序。我的应用程序随机崩溃并出现分段错误,我知道它必须是wxPython,因为我有一个相同代码的控制台版本,它不会崩溃。前端是一个只读表,其中的项目会自动从线程填充它。

我正在使用wxPython2.8和python 3.0版,我在Ubuntu 10.04上运行它。我不知道我做错了什么或是wxPython,如果是这样我应该报告错误?

我在eclipse调试模式下运行应用程序,运行一段时间后得到了这个:

Gdk:ERROR:/build/buildd/gtk+2.0-2.20.1/gdk/gdkregion-generic.c:337:miSetExtents: assertion failed: (pExtents->y1 < pExtents->y2)

我也通过安装python3.1-gdb,gdb使用apt-get install python3.1-gdb运行它并得到了这个:

Program received signal SIGSEGV, Segmentation fault. 
0xb76dcfa7 in wxGridCellAttr::GetRenderer(wxGrid*, int, int) const () from /usr/lib/libwx_gtk2u_adv-2.8.so.0

第二次与gdb合作并打电话给bt我得到了这个:

Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
Starting program: /usr/bin/python main.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb5c71b70 (LWP 10119)]
[New Thread 0xb53e4b70 (LWP 10120)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb5c71b70 (LWP 10119)]
0x00000061 in ?? ()
(gdb) bt
#0  0x00000061 in ?? ()
#1  0xb76e8209 in wxGrid::GetCellSize(int, int, int*, int*) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#2  0xb76e82bb in wxGrid::CellToRect(int, int) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#3  0xb76f6ee5 in wxGrid::SetCellValue(int, int, wxString const&) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#4  0xb607c45b in ?? () from /usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_grid.so
#5  0x080e0a57 in PyEval_EvalFrameEx ()
#6  0x080e2977 in PyEval_EvalCodeEx ()
#7  0x080e0fb3 in PyEval_EvalFrameEx ()
#8  0x080e20e7 in PyEval_EvalFrameEx ()
#9  0x080e2977 in PyEval_EvalCodeEx ()
#10 0x0816bdbf in ?? ()
#11 0x0806257a in PyObject_Call ()
#12 0x080df8d8 in PyEval_EvalFrameEx ()
#13 0x080e20e7 in PyEval_EvalFrameEx ()
#14 0x080e20e7 in PyEval_EvalFrameEx ()
#15 0x080e2977 in PyEval_EvalCodeEx ()
#16 0x0816bcdc in ?? ()
#17 0x0806257a in PyObject_Call ()
#18 0x0806a57c in ?? ()
#19 0x0806257a in PyObject_Call ()
#20 0x080db9f2 in PyEval_CallObjectWithKeywords ()
#21 0x0810ecf8 in ?? ()
#22 0xb7fb096e in start_thread (arg=0xb5c71b70) at pthread_create.c:300
#23 0xb7d3d3fe in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130

我第三次用bt再次运行它,我得到了这个:

Starting program: /usr/bin/python main.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb5c70b70 (LWP 13774)]
[New Thread 0xb53e3b70 (LWP 13826)]
*** glibc detected *** /usr/bin/python: double free or corruption (!prev): 0x08aec2b0
Program received signal SIGSEGV, Segmentation fault.
0xb72abcf0 in typeinfo name for wxObject () from /usr/lib/libwx_baseu-2.8.so.0
(gdb) bt
#0  0xb72abcf0 in typeinfo name for wxObject () from /usr/lib/libwx_baseu-2.8.so.0
#1  0xb76dbe59 in wxGridCellAttr::GetBackgroundColour() const () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#2  0xb76e4c8b in wxGridCellRenderer::Draw(wxGrid&, wxGridCellAttr&, wxDC&, wxRect const&, int, int, bool) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#3  0xb76f2ea4 in wxGridCellStringRenderer::Draw(wxGrid&, wxGridCellAttr&, wxDC&, wxRect const&, int, int, bool) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#4  0xb76eb579 in wxGrid::DrawCell(wxDC&, wxGridCellCoords const&) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#5  0xb76eb882 in wxGrid::DrawGridCellArea(wxDC&, wxGridCellCoordsArray const&) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#6  0xb76ece37 in wxGridWindow::OnPaint(wxPaintEvent&) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#7  0xb71eba9f in wxAppConsole::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&), wxEvent&) const () from /usr/lib/libwx_baseu-2.8.so.0
#8  0xb728a209 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from /usr/lib/libwx_baseu-2.8.so.0
#9  0xb728b2d4 in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () from /usr/lib/libwx_baseu-2.8.so.0
#10 0xb728b3d3 in wxEvtHandler::ProcessEvent(wxEvent&) () from /usr/lib/libwx_baseu-2.8.so.0
#11 0xb74770c2 in wxWindow::GtkSendPaintEvents() () from /usr/lib/libwx_gtk2u_core-2.8.so.0
#12 0xb7477688 in ?? () from /usr/lib/libwx_gtk2u_core-2.8.so.0
#13 0xb6dfa434 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#14 0xb6a0f252 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#15 0xb6a2399d in ?? () from /usr/lib/libgobject-2.0.so.0
#16 0xb6a24c33 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#17 0xb6a25256 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#18 0xb6f27646 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#19 0xb6df412b in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
#20 0xb6c6284b in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#21 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#22 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#23 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#24 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#25 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#26 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#27 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#28 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#29 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#30 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#31 0xb6c8bad4 in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#32 0xb6c5efa3 in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#33 0xb6c60fbf in gdk_window_process_all_updates () from /usr/lib/libgdk-x11-2.0.so.0
#34 0xb6c6103b in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#35 0xb6c3d358 in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#36 0xb695f661 in ?? () from /lib/libglib-2.0.so.0
#37 0xb69616e5 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#38 0xb69653d8 in ?? () from /lib/libglib-2.0.so.0
#39 0xb6965917 in g_main_loop_run () from /lib/libglib-2.0.so.0
#40 0xb6df43d9 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#41 0xb7460708 in wxEventLoop::Run() () from /usr/lib/libwx_gtk2u_core-2.8.so.0
#42 0xb74f34de in wxAppBase::MainLoop() () from /usr/lib/libwx_gtk2u_core-2.8.so.0
#43 0xb7a15b92 in wxPyApp::MainLoop() () from /usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core_.so
#44 0xb7a889da in ?? () from /usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core_.so
#45 0x080e0a57 in PyEval_EvalFrameEx ()
#46 0x080e2977 in PyEval_EvalCodeEx ()
#47 0x0816bcdc in ?? ()
#48 0x0806257a in PyObject_Call ()
#49 0x0806a57c in ?? ()
#50 0x0806257a in PyObject_Call ()
#51 0x080e0599 in PyEval_EvalFrameEx ()
#52 0x080e20e7 in PyEval_EvalFrameEx ()
#53 0x080e20e7 in PyEval_EvalFrameEx ()
#54 0x080e20e7 in PyEval_EvalFrameEx ()
#55 0x080e2977 in PyEval_EvalCodeEx ()
#56 0x080e2a77 in PyEval_EvalCode ()
#57 0x0810071d in PyRun_FileExFlags ()
#58 0x08100982 in PyRun_SimpleFileExFlags ()
#59 0x0805df7c in Py_Main ()
#60 0x0805d13b in main ()

我最后一次跑步时实际上得到了__kernel_vsyscall

Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
Starting program: /usr/bin/python main.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb5c71b70 (LWP 20640)]
[New Thread 0xb53e4b70 (LWP 20662)]
*** glibc detected *** /usr/bin/python: double free or corruption (!prev): 0x08aec298 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6e341)[0xb7cd8341]
/lib/tls/i686/cmov/libc.so.6(+0x6fb98)[0xb7cd9b98]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xb7cdcc7d]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb716d741]
/usr/lib/libwx_baseu-2.8.so.0(_ZN21wxClientDataContainerD0Ev+0x33)[0xb71ee293]
/usr/lib/libwx_gtk2u_adv-2.8.so.0(_ZN6wxGrid11GetCellSizeEiiPiS0_+0x59)[0xb76e8209]
/usr/lib/libwx_gtk2u_adv-2.8.so.0(_ZN6wxGrid10CellToRectEii+0xab)[0xb76e82bb]
/usr/lib/libwx_gtk2u_adv-2.8.so.0(_ZN6wxGrid12SetCellValueEiiRK8wxString+0x85)[0xb76f6ee5]
/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_grid.so(+0x1f45b)[0xb607c45b]
/usr/bin/python(PyEval_EvalFrameEx+0x40f7)[0x80e0a57]
/usr/bin/python(PyEval_EvalCodeEx+0x857)[0x80e2977]
/usr/bin/python(PyEval_EvalFrameEx+0x4653)[0x80e0fb3]
/usr/bin/python(PyEval_EvalFrameEx+0x5787)[0x80e20e7]
/usr/bin/python(PyEval_EvalCodeEx+0x857)[0x80e2977]
/usr/bin/python[0x816bdbf]
/usr/bin/python(PyObject_Call+0x4a)[0x806257a]
/usr/bin/python(PyEval_EvalFrameEx+0x2f78)[0x80df8d8]
/usr/bin/python(PyEval_EvalFrameEx+0x5787)[0x80e20e7]
/usr/bin/python(PyEval_EvalFrameEx+0x5787)[0x80e20e7]
/usr/bin/python(PyEval_EvalCodeEx+0x857)[0x80e2977]
/usr/bin/python[0x816bcdc]
/usr/bin/python(PyObject_Call+0x4a)[0x806257a]
/usr/bin/python[0x806a57c]
/usr/bin/python(PyObject_Call+0x4a)[0x806257a]
/usr/bin/python(PyEval_CallObjectWithKeywords+0x42)[0x80db9f2]
/usr/bin/python[0x810ecf8]
/lib/tls/i686/cmov/libpthread.so.0(+0x596e)[0xb7fb096e]
/lib/tls/i686/cmov/libc.so.6(clone+0x5e)[0xb7d3d3fe]
======= Memory map: ========
08048000-08229000 r-xp 00000000 08:01 12322846   /usr/bin/python2.6
08229000-0822a000 r--p 001e0000 08:01 12322846   /usr/bin/python2.6
0822a000-08279000 rw-p 001e1000 08:01 12322846   /usr/bin/python2.6
08279000-08b35000 rw-p 00000000 00:00 0          [heap]
b4a00000-b4a7b000 rw-p 00000000 00:00 0 
b4a7b000-b4b00000 ---p 00000000 00:00 0 
b4bb2000-b4be0000 r-xp 00000000 08:01 12717595   /usr/lib/python2.6/lib-dynload/pyexpat.so
b4be0000-b4be2000 r--p 0002d000 08:01 12717595   /usr/lib/python2.6/lib-dynload/pyexpat.so
b4be2000-b4be3000 rw-p 0002f000 08:01 12717595   /usr/lib/python2.6/lib-dynload/pyexpat.so
b4be3000-b4be4000 rw-p 00000000 00:00 0 
b4be4000-b4be5000 ---p 00000000 00:00 0 
b4be5000-b53e5000 rw-p 00000000 00:00 0 
b53e5000-b5471000 r--p 00000000 08:01 13370974   /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf
b5471000-b5472000 ---p 00000000 00:00 0 
b5472000-b5c72000 rw-p 00000000 00:00 0 
b5c72000-b5d0a000 r--p 00000000 08:01 13370975   /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf
b5d0a000-b5d14000 r-xp 00000000 08:01 4718773    /lib/libudev.so.0.6.1
b5d14000-b5d15000 r--p 00009000 08:01 4718773    /lib/libudev.so.0.6.1
b5d15000-b5d16000 rw-p 0000a000 08:01 4718773    /lib/libudev.so.0.6.1
b5d16000-b5d3a000 r-xp 00000000 08:01 12327322   /usr/lib/gio/modules/libgvfsdbus.so
b5d3a000-b5d3b000 r--p 00023000 08:01 12327322   /usr/lib/gio/modules/libgvfsdbus.so
b5d3b000-b5d3c000 rw-p 00024000 08:01 12327322   /usr/lib/gio/modules/libgvfsdbus.so
b5d3c000-b5d50000 r-xp 00000000 08:01 12324166   /usr/lib/libgvfscommon.so.0.0.0
b5d50000-b5d51000 r--p 00013000 08:01 12324166   /usr/lib/libgvfscommon.so.0.0.0
b5d51000-b5d52000 rw-p 00014000 08:01 12324166   /usr/lib/libgvfscommon.so.0.0.0
b5d6e000-b5da5000 r-xp 00000000 08:01 4718707    /lib/libdbus-1.so.3.4.0
b5da5000-b5da6000 r--p 00036000 08:01 4718707    /lib/libdbus-1.so.3.4.0
b5da6000-b5da7000 rw-p 00037000 08:01 4718707    /lib/libdbus-1.so.3.4.0
b5da7000-b5de0000 r-xp 00000000 08:01 12324182   /usr/lib/libibus.so.1.0.0
b5de0000-b5de1000 r--p 00039000 08:01 12324182   /usr/lib/libibus.so.1.0.0
b5de1000-b5de2000 rw-p 0003a000 08:01 12324182   /usr/lib/libibus.so.1.0.0
b5de7000-b5de9000 r-xp 00000000 08:01 12584487   /usr/lib/pango/1.6.0/modules/pango-basic-fc.so
b5de9000-b5dea000 r--p 00001000 08:01 12584487   /usr/lib/pango/1.6.0/modules/pango-basic-fc.so
b5dea000-b5deb000 rw-p 00002000 08:01 12584487   /usr/lib/pango/1.6.0/modules/pango-basic-fc.so
b5deb000-b5dfc000 r-xp 00000000 08:01 12327321   /usr/lib/gio/modules/libgioremote-volume-monitor.so
b5dfc000-b5dfd000 r--p 00011000 08:01 12327321   /usr/lib/gio/modules/libgioremote-volume-monitor.so
b5dfd000-b5dfe000 rw-p 00012000 08:01 12327321   /usr/lib/gio/modules/libgioremote-volume-monitor.so
b5dfe000-b5e03000 r-xp 00000000 08:01 12327767   /usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.so
b5e03000-b5e04000 r--p 00004000 08:01 12327767   /usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.so
b5e04000-b5e05000 rw-p 00005000 08:01 12327767   /usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.so
b5e05000-b5e06000 r--s 00000000 08:01 11796545   /var/cache/fontconfig/c05880de57d1f5e948fdfacc138775d9-le32d4.cache-3
b5e06000-b5e0c000 r--s 00000000 08:01 11796542   /var/cache/fontconfig/945677eb7aeaf62f1d50efc3fb3ec7d8-le32d4.cache-3
b5e0c000-b5e0e000 r--s 00000000 08:01 11796543   /var/cache/fontconfig/99e8ed0e538f840c565b6ed5dad60d56-le32d4.cache-3
b5e0e000-b5e11000 r--s 00000000 08:01 11796552   /var/cache/fontconfig/e383d7ea5fbe662a33d9b44caf393297-le32d4.cache-3
b5e11000-b5e13000 r--s 00000000 08:01 11803601   /var/cache/fontconfig/ea47318ec9849e1a71e80a5d69d13859-le32d4.cache-3
b5e13000-b5e14000 r--s 00000000 08:01 11803600   /var/cache/fontconfig/e3fa16a14183b06aa45b3e009278fd14-le32d4.cache-3
b5e14000-b5e15000 r--s 00000000 08:01 11796553   /var/cache/fontconfig/e7071f4a29fa870f4323321c154eba04-le32d4.cache-3
b5e15000-b5e17000 r--s 00000000 08:01 11804137   /var/cache/fontconfig/b5ea634b0fb353b8ea17632d1f9ef766-le32d4.cache-3
b5e17000-b5e1a000 r--s 00000000 08:01 11796539   /var/cache/fontconfig/6eb3985aa4124903f6ff08ba781cd364-le32d4.cache-3
b5e1a000-b5e1b000 r--s 00000000 08:01 11796535   /var/cache/fontconfig/4c73fe0c47614734b17d736dbde7580a-le32d4.cache-3
b5e1b000-b5e1c000 r--s 00000000 08:01 11796529   /var/cache/fontconfig/0d8c3b2ac0904cb8a57a757ad11a4a08-le32d4.cache-3
b5e1c000-b5e1d000 r--s 00000000 08:01 11796537   /var/cache/fontconfig/6a53c69dea097a2d716e069445527da8-le32d4.cache-3
b5e1d000-b5e21000 r--s 00000000 08:01 11796544   /var/cache/fontconfig/a755afe4a08bf5b97852ceb7400b47bc-le32d4.cache-3
b5e21000-b5e28000 r--s 00000000 08:01 11803865   /var/cache/fontconfig/6d41288fd70b0be22e8c3a91e032eec0-le32d4.cache-3
b5e28000-b5e33000 r--s 00000000 08:01 11796530   /var/cache/fontconfig/0f34bcd4b6ee430af32735b75db7f02b-le32d4.cache-3
b5e33000-b5e55000 r--s 00000000 08:01 11803842   /var/cache/fontconfig/365b55f210c0a22e9a19e35191240f32-le32d4.cache-3
b5e55000-b5e5d000 r--s 00000000 08:01 11796548   /var/cache/fontconfig/d52a8644073d54c13679302ca1180695-le32d4.cache-3
b5e5d000-b5e87000 r-xp 00000000 08:01 12327750   /usr/lib/gtk-2.0/2.10.0/engines/libclearlooks.so
b5e87000-b5e88000 r--p 00029000 08:01 12327750   /usr/lib/gtk-2.0/2.10.0/engines/libclearlooks.so
Program received signal SIGABRT, Aborted.
[Switching to Thread 0xb5c71b70 (LWP 20640)]
0xb7fe2430 in __kernel_vsyscall ()

1 个答案:

答案 0 :(得分:4)

首先,wxPython 2.8不适用于Python 3,因此部分描述没有意义。有一个wxPython 2.9 Phoenix版本可以与Python 3一起使用,但它现在是预测试版。

您提到您正在通过线程更新Grid小部件。如果你实际上是在一个线程中直接设置了一个单元格的值(即myGrid.SetCellValue()),那么你就是错误地做了。 wxPython具有线程安全的方法,必须用于从线程到GUI的通信。这些如下:

  • wx.CallAfter
  • wx.CallLater
  • wx.PostEvent

您应阅读以下文章,了解其工作原理示例:

这些方法适用于从线程到wxPython GUI的任何类型的交互,而不仅仅是在更新网格时。例如,您可能需要更新文本或列表控件。如果是这样,您仍然需要使用上述方法之一。

正如@multiphrenic所提到的,你应该创建一个小的可运行的示例应用程序来显示你遇到的问题。您可以在wxPython wiki上阅读有关如何执行此操作的所有信息。