def __init__ (self, func):
        """ Initialize a new GtkWorker around a specific function """
        
        # WARNING: This deadlocks if calling code already has the gdk lock and
        # is not the MainThread
        if type(currentThread()) != _MainThread:
            threads_enter()
        GObject.__init__(self)
        if type(currentThread()) != _MainThread:
            threads_leave()
        
        Thread.__init__(self)
        self.setDaemon(True)
        
        # By some reason we cannot access __gsignals__, so we have to do a
        # little double work here
        self.connections = {"progressed": 0, "published": 0, "done": 0}
        self.handler_ids = {}
        
        self.func = func
        self.cancelled = False
        self.done = False
        self.progress = 0
        
        ########################################################################
        # Publish and progress queues                                          #
        ########################################################################
        
        class Publisher (Thread):
            SEND_LIST, SEND_LAST = range(2)
            
            def __init__ (self, parrent, queue, signal, sendPolicy):
                Thread.__init__(self)
                self.setDaemon(True)
                self.parrent = parrent
                self.queue = queue
                self.signal = signal
                self.sendPolicy = sendPolicy
            
            def run (self):
                while True:
                    v = self.queue.get()
                    if v == None:
                        break
                    threads_enter()
                    l = [v]
                    while True:
                        try:
                            v = self.queue.get_nowait()
                        except Queue.Empty:
                            break
                        else: l.append(v)
                    try:
                        if self.sendPolicy == self.SEND_LIST:
                            self.parrent.emit(self.signal, l)
                        elif self.sendPolicy == self.SEND_LAST:
                            self.parrent.emit(self.signal, l[-1])
                    finally:
                        threads_leave()
        
        self.publishQueue = Queue.Queue()
        self.publisher = Publisher (
                self, self.publishQueue, "published", Publisher.SEND_LIST)
        self.publisher.start()
        
        self.progressQueue = Queue.Queue()
        self.progressor = Publisher (
                self, self.progressQueue, "progressed", Publisher.SEND_LAST)
        self.progressor.start()
 Initialize a new GtkWorker around a specific function 
recipes/Python/521881_GtkWorker/recipe-521881.py