Threading in pygtk is, um, well, you've got to be careful ;)  Because of
the way python threads, and the fact that the gtk stuff isn't properly
wrapped (I _did_ take a couple of shots at wrapping it, btw, but it's beyond
the amount of time I have spare to fix :(, simply spawning a thread and
calling main_loop() in that thread won't work - at least, not well.

The best solution I've found so far is similar to following:

At the start of the thread, when you've set up your windows:

        timeout_add(1000,self._fiddleLock)
        print 'DEBUG: %s starting main loop' % self.threadName
        mainloop()

self._fiddleLock reads:

    def _fiddleLock(self):
# Release the lock, give other tasks a chance to do stuff, then acquire
# it again - acquire will block.
        try:
            self.threadLock.release()
        except AssertionError:
            pass
        else:
            time.sleep(0.1)
            self.threadLock.acquire()
        timeout_add(100,self._fiddleLock)

So you go into main_loop, which will do mostly gtk stuff, and every so often
you pop out, and put that thread to sleep _in python_, which means other
pythonic threads have a chance to run.  The timing of the two numbers above
will probably depend on what level of responsiveness you're aiming for, and
how much you want to impact your other python threads.

If anyone else out there has better ways of dealing with this stuff, I'd love
to hear them - the above works for my program, but _feels_ kludgy...

(Oh, there's also 'mainiteration', which may help you - calling that
periodically during your calculations - without bothering to thread at all
- may be a better solution for you...)

>>> Lars Hoss wrote
> Hi everyone,
> 
> I am new to this list, so I do not know wether
> this question was asked by someone else.
> 
> I am working on a litle tool which helps me to
> synchronize two databases on different hosts.
> Now if I push the go button I want to show
> the progress with a progress bar. but
> due to the heavy calculations the GUI is frozen.
> So I tried to put the calculations into an extra thread,
> but this seems not to work?
> 
> Anyone who can help me?
> 
> Thanx in advance,
> Lars
> To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
> 

--------------- [EMAIL PROTECTED] ---------------
Kevin Littlejohn,
Technical Architect, Connect.com.au
Don't anthropomorphise computers - they hate that.
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to