minidom + wxPython woes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lonnie Princehouse

    #1

    minidom + wxPython woes

    Hi all,

    I'm getting a seg fault when I try to use minidom to parse some XML
    inside a wxPython app.

    I was wondering if someone else could run the simple code below on
    Linux and, if it doesn't crash horribly, post which versions of
    (Python, wxPython) they are using? I can't find other messages related
    to this, so I suspect it is something broken with my installation.
    I'm using Python 2.4.2 and wx 2.6.1.0.

    Incidentally, writing XML with minidom works fine, and this is all
    happening in wxPython's main thread.


    import wx
    from xml.dom import minidom

    app = wx.PySimpleApp( )
    frame = wx.Frame(None, -1, "Hello World")
    frame.Show(True )
    button = wx.Button(frame , -1, "Click me")

    testxml = 'xml version="1.0" ?><foo></foo>'

    def click(event):
    doc = minidom.parseSt ring(testxml) # seg fault?!
    print "Success!"

    frame.Bind(wx.E VT_BUTTON, click, button)

    app.MainLoop()

  • Lonnie Princehouse

    #2
    Re: minidom + wxPython woes

    Oops, I missed a bracket... that should read:

    testxml = '<xml version="1.0" ?><foo></foo>'

    But it still crashes ;-)

    Comment

    • Peter Hansen

      #3
      Re: minidom + wxPython woes

      Lonnie Princehouse wrote:[color=blue]
      > Oops, I missed a bracket... that should read:
      >
      > testxml = '<xml version="1.0" ?><foo></foo>'
      >
      > But it still crashes ;-)[/color]

      Maybe missing a question mark still too?

      <?xml version="1.0"?>

      (It's like a processing instruction, not an element.)

      -Peter

      Comment

      • Frank Millman

        #4
        Re: minidom + wxPython woes


        Lonnie Princehouse wrote:[color=blue]
        > Hi all,
        >
        > I'm getting a seg fault when I try to use minidom to parse some XML
        > inside a wxPython app.
        >
        > I was wondering if someone else could run the simple code below on
        > Linux and, if it doesn't crash horribly, post which versions of
        > (Python, wxPython) they are using? I can't find other messages related
        > to this, so I suspect it is something broken with my installation.
        > I'm using Python 2.4.2 and wx 2.6.1.0.
        >
        > Incidentally, writing XML with minidom works fine, and this is all
        > happening in wxPython's main thread.
        >
        >
        > import wx
        > from xml.dom import minidom
        >
        > app = wx.PySimpleApp( )
        > frame = wx.Frame(None, -1, "Hello World")
        > frame.Show(True )
        > button = wx.Button(frame , -1, "Click me")
        >
        > testxml = 'xml version="1.0" ?><foo></foo>'
        >
        > def click(event):
        > doc = minidom.parseSt ring(testxml) # seg fault?!
        > print "Success!"
        >
        > frame.Bind(wx.E VT_BUTTON, click, button)
        >
        > app.MainLoop()[/color]

        This sounds similar to a problem I reported a few months ago. This is
        the link.



        In my case, it turned out to be a bug in the pyexpat module - it is
        known about, but for some reason difficult to fix, so it is still
        there.

        I found a workaround, which is documented in the above thread.

        HTH

        Frank Millman

        Comment

        • Fredrik Lundh

          #5
          Re: minidom + wxPython woes

          Frank Millman wrote:
          [color=blue]
          > This sounds similar to a problem I reported a few months ago. This is
          > the link.
          >[/color]
          http://groups.google.com/group/comp....bdf493f3c38942[color=blue]
          >
          > In my case, it turned out to be a bug in the pyexpat module - it is
          > known about, but for some reason difficult to fix, so it is still
          > there.[/color]

          no, it's not a bug in the pyexpat module -- the problem is that
          wxPython uses it's own incompatible version of the expat library,
          and loads it in a way that causes problems for any library that's
          tries to use its own statically linked version.

          see MvL's comments in the sourceforge tracker for more info.

          </F>



          Comment

          • Frank Millman

            #6
            Re: minidom + wxPython woes


            Fredrik Lundh wrote:[color=blue]
            > Frank Millman wrote:
            >[color=green]
            > > This sounds similar to a problem I reported a few months ago. This is
            > > the link.
            > >[/color]
            > http://groups.google.com/group/comp....bdf493f3c38942[color=green]
            > >
            > > In my case, it turned out to be a bug in the pyexpat module - it is
            > > known about, but for some reason difficult to fix, so it is still
            > > there.[/color]
            >
            > no, it's not a bug in the pyexpat module -- the problem is that
            > wxPython uses it's own incompatible version of the expat library,
            > and loads it in a way that causes problems for any library that's
            > tries to use its own statically linked version.
            >
            > see MvL's comments in the sourceforge tracker for more info.
            >
            > </F>[/color]

            I had a look at the sourceforge tracker. I did not understand much of
            it - rather too technical for me. There are two points worth noting.

            Firstly, it seems from various posts to the tracker item that the same
            problem has been reported with pygtk, Qt, and VTK.

            Secondly, in tracker item 1295808 (which, according to the notes, is
            actually the same bug), there is talk of submitting a patch in 2.5 to
            address the issue.

            It seems to me (FWIW - as I said, I do not really understand much of
            what I read) that it may not technically be a bug in pyexpat, but there
            is a real issue there, and the decision has been taken to make a change
            to pyexpat so that the problem will not arise in the future.

            Frank

            Comment

            • Paul Boddie

              #7
              Re: minidom + wxPython woes

              Frank Millman wrote:[color=blue]
              > Fredrik Lundh wrote:[color=green]
              > >
              > > no, it's not a bug in the pyexpat module -- the problem is that
              > > wxPython uses it's own incompatible version of the expat library,
              > > and loads it in a way that causes problems for any library that's
              > > tries to use its own statically linked version.[/color][/color]

              [...]
              [color=blue]
              > Firstly, it seems from various posts to the tracker item that the same
              > problem has been reported with pygtk, Qt, and VTK.[/color]

              There used to be issues with Expat, PyXML and mod_python which may be
              vaguely related to this, mostly because there was some usage of Expat
              within some Apache component which conflicted with PyXML's Expat
              configuration. In the end, I just dropped PyXML and started using other
              libraries not affected by such issues, and I'm not totally sure that
              anyone really resolved the problem definitively (although this was
              possibly four or five years ago, so a lot can have happened since).

              Paul

              Comment

              • Lonnie Princehouse

                #8
                Re: minidom + wxPython woes

                I'm hesitant to resort to tricks like "import pyexpat before wx, so
                that symbols are loaded from the right library".

                Luckily, I stumbled onto pxdom. It's a pure-python DOM implementation,
                and switching to it was as easy as this:

                # import xml.dom.minidom as dom
                import pxdom as dom

                Comment

                • grahamd@dscpl.com.au

                  #9
                  Re: minidom + wxPython woes

                  Paul Boddie wrote:[color=blue]
                  > Frank Millman wrote:[color=green]
                  > > Fredrik Lundh wrote:[color=darkred]
                  > > >
                  > > > no, it's not a bug in the pyexpat module -- the problem is that
                  > > > wxPython uses it's own incompatible version of the expat library,
                  > > > and loads it in a way that causes problems for any library that's
                  > > > tries to use its own statically linked version.[/color][/color]
                  >
                  > [...]
                  >[color=green]
                  > > Firstly, it seems from various posts to the tracker item that the same
                  > > problem has been reported with pygtk, Qt, and VTK.[/color]
                  >
                  > There used to be issues with Expat, PyXML and mod_python which may be
                  > vaguely related to this, mostly because there was some usage of Expat
                  > within some Apache component which conflicted with PyXML's Expat
                  > configuration.[/color]

                  FYI, the incompatibility issues that arise with pyexpat in mod_python
                  are well documented at:



                  Graham

                  Comment

                  • Paul Boddie

                    #10
                    Re: minidom + wxPython woes

                    grah...@dscpl.c om.au wrote:[color=blue]
                    >
                    > FYI, the incompatibility issues that arise with pyexpat in mod_python
                    > are well documented at:
                    >
                    > http://www.dscpl.com.au/articles/modpython-006.html[/color]

                    Nice document! Is there some possibly-similar explanation of character
                    encoding issues with mod_python and Expat somewhere, too, or is that
                    problem long forgotten?

                    Paul

                    Comment

                    Working...