[wxPython] Trouble with threading

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Trouble with threading

Johan Lübcke
Hi,

I have trouble with threading messing up eventhandling. The following
program works if the statement starting the other thread is
removed. Have I missed something central in how to handle the layout
of a panel?

   / Johan Lubcke

----- 8< -----

from wxPython.wx import *
from wxPython.lib.grids import wxFlexGridSizer

from threading import Thread
def foo(): print "Fooing!"
Thread(target=foo).start()

class MyFrame(wxFrame):
    def __init__(self, parent, ID, title, pos, size):
        wxFrame.__init__(self, parent, ID, title, pos, size)
        panel = wxPanel(self, -1)
        self.panel=panel
        box = wxFlexGridSizer(1, 2, 10, 10)
        box.Add(wxButton(panel, -1, "Foo"), 0, wxCENTER)
        box.Add(wxButton(panel, -1, "Bar"), 0, wxCENTER)
        box.AddGrowableCol(1)
        panel.SetSizer(box)
        EVT_SIZE(panel, lambda e, p=panel: p.Layout())

class MyApp(wxApp):
    def OnInit(self):
        win = MyFrame(None, -1, "Bummer", wxDefaultPosition, (200, 100))
        win.Show(true)
        self.SetTopWindow(win)
        return true

MyApp(0).MainLoop()


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Trouble with threading

Robin Dunn
There is currently an issue with threads that I am working on.  I'm guessing
that there is a deadlock in aquiring the Python Interpreter Lock when the
events happen. The odd thing is that in some samples threads work just fine,
others liek this one lock up.

Thanks for the simple sample.  It will help track down the trouble.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Trouble with threading

Robin Dunn
In reply to this post by Johan Lübcke
Hi All,

Just wanted to let you know that I have solved the threading issue.  It was
a pain in the arse for just a one line change, but I now know a WHOLE LOT
more about Python's threads...

The new code is in CVS and will be in the next release in a week or so.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Trouble with threading

Robin Dunn
>
> | I now know a WHOLE LOT more about Python's threads...
>                ^^^^^^^^^
>
> Now, that makes me curious.
> Will you drop us (that's the list) a few lines about your insight?
>

I had to compile Python in debug mode and trace through some of its code, so
I was refering to what I picked up by seeing the magic firsthand instead of
just its effects from outside the box.

BTW, this is the first time on this project I have had to trace through
Python code to solve a problem, which I think is a testament to the quality
and understandability of the Python C-API.

BTW#2, I've just found another case of what looks like
interpreter-deadlock-itus, (in OGL) so I guess my announcment last night was
a little premature...

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Trouble with threading

Robin Dunn
> BTW#2, I've just found another case of what looks like
> interpreter-deadlock-itus, (in OGL) so I guess my announcment last night
was
> a little premature...
>

Found it.  Another case of a very small and obscure amount of code causing
large amounts of trouble and debugging time.  It's on its way to CVS for
those who want to stay on top of the fixes.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users