[Python-Dev] Twisted Isn't Specific (was Re: Trial balloon: microthreads library in stdlib)

Bob Ippolito bob at redivi.com
Thu Feb 15 22:26:24 CET 2007


On 2/15/07, Baptiste Carvello <baptiste13 at altern.org> wrote:
> >> Ah, threads :-( It turns out that you need to invoke GetMessage in the
> >> context of the thread in which the window was created. In a different
> >> thread, you won't get any messages.
> >
> > I'd be interested to hear about other situations where threading would
> > cause a problem.  My suspicion is that Windows is the hard one, and as
> > I've shown that one is solvable.
> >
> >
> I've tried something similar on Linux, with gtk an wx.
>
> You can run the gtk main loop in its own thread, but because gtk is not thread
> safe, you have to grab a mutex everytime you run gtk code outside the thread the
> mainloop is running in. So you have to surround your calls to the gtk api with
> calls to gtk.threads_enter and gtk.threads_leave. Except for callbacks of
> course, because they are executed in the main thread... Doable, but not fun.
>
> The same goes for wx. Then all hell breaks loose when you try to use both gtk
> and wx at the same time. That's because on Linux, the wx main loop calls the gtk
> mainloop behind the scenes. As far as I know, that problem can not be solved
> from python.
>
> So yes that strategy can work, but it's no silver bullet.

And it's worse on Windows and Mac OS X where some GUI API calls *must*
happen on a particular thread or they simply don't work.

-bob


More information about the Python-Dev mailing list