[pygtk] freeze problem
Víctor M. Hernández Rocamora
victor.hr at gmail.com
Tue Mar 15 06:21:56 WST 2005
Reading the python reference I've found a paragraph that explains this
behaviour:
# From gtk.gdk.theads_init reference:
Signal handlers are automatically invoked within a gdk_threads_enter()
and gdk_threads_leave() function pair by GTK so the
gtk.gdk.threads_enter() and gtk.gdk.threads_leave() functions should
not be called within a Python signal handler or the application will
deadlock. However, idle, timeout and input handlers are executed
outside the GGL so these should use the gtk.gdk.threads_enter() and
gtk.gdk.threads_leave() functions if PyGTK methods or functions are
called.
###############
A threading tutorial for PyGTK is urgently needed, some charitable
guru there? ;-)
On Mon, 14 Mar 2005 22:55:35 +0100, Víctor M. Hernández Rocamora
<victor.hr at gmail.com> wrote:
> The problem is that window class is not running in another thread,
> actually, and when you call d.run() in the button click handler, the
> theads_enter() statement freezes your app.
> You can make a run method to be called from the window without
> theads_enter() and threads_leave():
>
> def run_no_thread(self):
> """You call this form window class()"""
>
> print 'no threads'
> rep = self.dialog.run()
> blah, blah...
>
> return passphrase, save_passphrase_checkbutton.get_active()
>
> def run(self):
> """You call this form plugin() class"""
> gtk.gdk.threads_enter()
> the same stuff from run_no_threads()
> gtk.gdk.threads_leave()
> return passphrase, save_passphrase_checkbutton.get_active()
>
> Or you can just define a param for run() telling if it is called form
> a thead or not:
>
> def run(self, in_thread=False):
> if in_thread:
> gtk.gdk.threads_enter()
> ...stuff...
> if in_thread:
> gtk.gdk.threads_leave()
> return passphrase, save_passphrase_checkbutton.get_active()
>
> I'm afraid I'm not an expert on threading so I don't know really
> what's the best design, but I hope this helps you.
>
> On Mon, 14 Mar 2005 22:13:26 +0100, Le Boulanger Yann
> <asterix at lagaule.org> wrote:
> > Víctor M. Hernández Rocamora wrote:
> > > Hi, you have to put all the gtk calls running in a different thread,
> > > between a gtk.gdk.threads_enter() and a gtk.gdk.threads_leave(). I've
> > > a attached a modifed test.py that works in my system.
> > >
> > > Good look!
> >
> > First thanks a lot for your answer, it works here too.
> > But, if I add a button in the windows to open the dialog, it freezes at
> > the call of gtk.gdk.threads_enter() line 31.
> > I reattached my small app with the button.
> >
> > Do you have an idea ?
> >
> >
> >
>
More information about the pygtk
mailing list