Re: [pygtk] freeze problem
Víctor M. Hernández Rocamora wrote: 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. great it works now, thanks a lot for your help Yann ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] freeze problem
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 pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] freeze problem
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 pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] freeze problem
Brian wrote: On Mon, 2005-14-03 at 13:23 +0100, Le Boulanger Yann wrote: Hi, I've a problem when I use gtk.Dialog.run() funtion in a thread I attached a small example that shows the problem. If you run test.py, it works (in this case threads are not used). But now if you run core.py (which launch a thread that does exactly the same thing) when I press a key in the dialog window, the dialog is not destroyed and the application freezes. I don't understand why this happens and what can I do to have it working with threads. My intention is from the thread to run() the dialog and wait for the user to give the password and then use it. run() would normally do this, but it freezes with threads. I saw a workaround in FAQ 10.17 (about dialog.run running in the mainloop), but that won't block in a mainloop so it doesn't suit me. does someone has an idea ? You are running the dialog from a thread which is not good. You should run all gui stuff from the main thread, even if they are controlled by other threads. Here is an example of thread safe communication and control that can easily be changed to do what you were trying to do in your core.py. The dispatcher function in this example can pass arbitrary data between threads as long as each party knows what to expect. This makes it very universal so that it can be used by many different threads with different data passing needs. Thanks for your answer, but the problem is that I use gtk ONLY in my thread : it's a plugin of my application. the core can be launched without the gtk plugin in a console. So I have to run gtk in my thread. Yann ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] freeze problem
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 ? test.tar.gz Description: application/gzip ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] freeze problem
On Mon, 2005-14-03 at 13:23 +0100, Le Boulanger Yann wrote: > Hi, > > I've a problem when I use gtk.Dialog.run() funtion in a thread > I attached a small example that shows the problem. > If you run test.py, it works (in this case threads are not used). > But now if you run core.py (which launch a thread that does exactly the > same thing) when I press a key in the dialog window, the dialog is not > destroyed and the application freezes. > I don't understand why this happens and what can I do to have it working > with threads. > My intention is from the thread to run() the dialog and wait for the > user to give the password and then use it. run() would normally do this, > but it freezes with threads. I saw a workaround in FAQ 10.17 (about > dialog.run running in the mainloop), but that won't block in a mainloop > so it doesn't suit me. > > does someone has an idea ? You are running the dialog from a thread which is not good. You should run all gui stuff from the main thread, even if they are controlled by other threads. Here is an example of thread safe communication and control that can easily be changed to do what you were trying to do in your core.py. The dispatcher function in this example can pass arbitrary data between threads as long as each party knows what to expect. This makes it very universal so that it can be used by many different threads with different data passing needs. -- Brian <[EMAIL PROTECTED]> dispatcher.py Description: application/python ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] freeze problem
Hi, I've a problem when I use gtk.Dialog.run() funtion in a thread I attached a small example that shows the problem. If you run test.py, it works (in this case threads are not used). But now if you run core.py (which launch a thread that does exactly the same thing) when I press a key in the dialog window, the dialog is not destroyed and the application freezes. I don't understand why this happens and what can I do to have it working with threads. My intention is from the thread to run() the dialog and wait for the user to give the password and then use it. run() would normally do this, but it freezes with threads. I saw a workaround in FAQ 10.17 (about dialog.run running in the mainloop), but that won't block in a mainloop so it doesn't suit me. does someone has an idea ? test.tar.gz Description: application/gzip ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/