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
<[EMAIL PROTECTED]> 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
> <[EMAIL PROTECTED]> 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 ?
> >
> >
> >
>
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to