Re: Long running nautilus extensions



Yes. As Nickolay also points out you have to dig into the threading
documentation on www.pygtk.org.

You would probably want to pass control back to Nautilus as soon as
possible and then finish your threads of with a callback, instead of
waiting for them.

Note that when using threads it is also important to do the following
instead of just entering gtk.main () as normally:

gtk.threads_init()
gtk.threads_enter ()
gtk.main ()
gtk.threads_leave ()

- and then each time your threads use gtk put gtk.threads_enter () and
gtk.threads_leave () around that block of code. Well you'll find more
about that on www.pygtk.org.


> > I'm not sure if this is the right place to ask, so if I should be asking
> > this somewhere else could somebody please direct me.

I'm not sure either, but the best thing would prolly be IRC #pygtk on
GIMPNet and/or #python on FreeNode . . .

Good luck,
Mikkel


On Fri, 2005-06-17 at 01:53 +0400, Nickolay V. Shmyrev wrote:
> В Чтв, 16/06/2005 в 20:08 +0000, Lorenzo E. Danielsson пишет:
> > Hi all,
> > 
> > I'm not sure if this is the right place to ask, so if I should be asking
> > this somewhere else could somebody please direct me.
> > 
> > I'm writing an extension using the Python Nautilus extension that
> > converts Mp3 files to Ogg. I create a thread for each file to be
> > converted. While the threads are running I keep the main thread alive
> > by:
> > 
> > while threading.activeCount() > 1:
> > 	time.sleep(3)
> > 
> > The problem is that this causes Nautilus to freeze until the selected
> > files have all been converted. I understand this is because I'm running
> > the extension in the main loop of Nautilus (correct me if I'm wrong). Is
> > there any way to work around this? How do I allow for an extension to
> > run for an extended period of time without blocking Nautilus itself. Is
> > there any call I can make within the loop that will allow Nautilus to do
> > its own processing and then return?
> > 
> > Lorenzo
> > 
> Right, you are just make process sleep instead of processing events.
> 
> There are number of ways to do it. The closest to your current
> implementation is usage
> of gobject.timeout_add but probably it also may have sense to emit
> signals in your threads
> when they finish tasks and in main thread just connect to signal. 
> 
> www.pygtk.org has a number of tutorials that may help you with this kind
> of question.
> 
-- Feeling contemplative when you should feel charming? terrible
staplers might help you.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]