Hi,

I'm working on NautilusSVN, a Python-based extension to integrate
Subversion into Nautilus. I've run into some confusing issues regarding
threading and I was hoping for some advice.

Basically, what I've found is that threads spawned by the Python
extension do not run unless the user specifically interacts with
Nautilus (eg. refreshes, selects files, opens context menu).

I've attached some code - it's the smallest possible example (I think)
that illustrates the problem. Drop it in ~/.nautilus/python-extensions
and use "nautilus -q && nautilus --no-desktop" to kill and restart
nautilus and log to the console.

What I would expect is that the test extension logs once every 1/100th
of a second. What actually happens is that it only logs when I interact
with Nautilus.

So what exactly is happening here? Is it expected?

I would appreciate any advice on this.

Just some background: one of the previous maintainers for this project
had the same problems[1], but I couldn't find any resolution. I asked a
few days ago on the Nautilus Dev list[2], and I was directed here.

Cheers,
Jason Heeris

[1] http://mail.gnome.org/archives/nautilus-list/2006-December/msg00053.html

[2] http://mail.gnome.org/archives/nautilus-list/2009-July/msg00000.html

PS. I think a 48 hour moderation queue might just be a little on the
extreme side... :)

'''
AsyncTest.py

Created on 27/06/2009

This is an attempt to create the simplest possible test for threading in a
Python extension for Nautilus.

@author: Jason Heeris
'''

import nautilus
import gobject

import threading
import time

import logging
        
class AsyncTest(nautilus.MenuProvider):
    ''' Simple test class for multithreaded Python Nautilus extension.
    '''
    
    def __init__(self):
        logging.getLogger().setLevel(logging.DEBUG)
    
    def get_background_items(self, window, files):
        '''
        Gets the context menu entry.
        '''
        menu_item = nautilus.MenuItem(
            'AsyncTest',
            'Test Async. Behaviour',
            'Tests multithreading in python-nautilus extensions'
        )
        
        menu_item.connect('activate', self.test_asynchronicity)
        
        return [menu_item]
        
    def test_asynchronicity(self, *args, **kwargs):
        '''
        This is a function to test doing things asynchronously.
        '''
              
        def asynchronous_function():
            
            logging.getLogger().setLevel(logging.DEBUG)

            logging.debug('\n%s Inside asynchronous_function()' % time.time())         
            
            for i in range(1, 21):
                time.sleep(0.01)
                logging.debug('%s %0i Asynchronous thread still running...' % (time.time(), i))
                logging.debug('Current thread: %s' % threading.currentThread())
                logging.debug('Is demon: %s' % threading.currentThread().isDaemon())
            
            logging.debug("%s asynchronous_function() finished\n" % time.time())
        
        # Calling threads_init does not seem to do anything.
        logging.debug('Current thread: %s' % threading.currentThread())
        gobject.threads_init()
        threading.Thread(target=asynchronous_function, name='Async Test').start()

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to